/*******************************************************************************
 * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
 * @file     bsp.c
 * @author   UartTFT Application Team
 * @version  V0.0.1
 * @date     2023-01-11
 * @brief    This file provides UartTFT Application display function
 ********************************************************************************/
 
#include "msFlash_UID.h"
#include "bsp.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "bsp_user.h"
#include "pit.h"
#include "tp_ctp.h"
#include "tp_rtp.h"
#include "iic.h"
#include "data.h"
#include "wav_dac.h"
#include "reset_drv.h"
#include "levetop.h"
#include "function_drv.h"
#include "uart_update.h"
#include "sincos_table.h"
#include "eflash_drv.h"
#include "iomacros.h"
#define MiMa_X 0
#define MiMa_Y 0

uint8_t Password_flag=0;
uint8_t Touch_flag = 0;//触摸功能标志
uint8_t Button_flag = 0;//按键功能标志
uint8_t Lock_mark_flag = 0;//长换锁功能标志
uint8_t TouchON_flag = 0;//正在触摸标志
uint8_t Language_state = 0;//语言记录
uint8_t Backlight_state = 0;//背光记录
uint8_t Sleep_time_state = 0;//睡眠时间记录
uint8_t Reset_flag = 0;

uint32_t Mode1_count_ALL=0;
uint32_t Mode2_count_ALL=0;
uint32_t Mode3_count_ALL=0;
uint32_t Count_value_ALL=0;

uint32_t Mode1_count=0;
uint32_t Mode2_count=0;
uint32_t Mode3_count=0;
uint32_t Count_value=0;

uint8_t Mode_Flag=0;

uint32_t Display_Layer = 0;
uint8_t Flash_type = 1;

uint16_t Mode_I_Sum=0;
uint16_t Mode_II_Sum=0;
uint16_t Mode_III_Sum=0;

uint8_t  Pic_lock_flag=0;
uint32_t Gif_addr;				//红色GIF的地址
uint8_t Double_finger_flag=0;	//双指标志位
uint16_t Double_finger_sum=0;	//双指按下计数
uint8_t Long_press_lock=0;
uint8_t disp_lock_pic=0;
uint8_t touch_nolock_flag=0;		//型号界面关密码
uint16_t touch_nolock_time=0;	
uint8_t Lmode_flag;
//================================================
/*configuration parameter variable*/
uint8_t buzzer = 0;
uint16_t Start_page = 0;
uint8_t SCI_C0 = 0x5A;
uint8_t SCI_C1 = 0xA5;
uint8_t CRC_Enable_Flag = 0;
uint8_t CRC_Feedback_Flag = 1;
uint8_t Screen_DIR = 0;
uint8_t TFT_bitcolor = 0;
uint8_t parity_flag = 0;	//CJC

/*ModBus operating variables*/
uint16_t Cnt_ModbusTX = 0; // record the offset position of Modbus operation parameters
uint16_t Sum_ModbusTX = 0; // total length of Modbus operation parameters

/*picture information*/
uint16_t pic_id = 0;
uint16_t pic_id_temp = 0;
uint32_t pic_add = 0;
uint16_t pic_w = 0;
uint16_t pic_h = 0;
uint32_t pic_len = 0;
uint8_t pic_flag = 0;

/*backlight information*/
//#if (LT269_SCREEN != 2)
uint16_t gDutyBuf[64] = {0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192,
						 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392,
						 400, 408, 416, 424, 432, 440, 448, 456, 464, 472, 480, 488, 496, 500};
//#else
//uint16_t gDutyBuf[64] = {500, 496, 488, 480, 472, 464, 456, 448, 440, 432, 424, 416, 408, 400,
//						 392, 384, 376, 368, 360, 352, 344, 336, 328, 320, 312, 304, 296, 288, 280, 272, 264, 256, 248, 240, 232, 224, 216, 208, 200,
//						 192, 184, 176, 168, 160, 152, 144, 136, 128, 120, 112, 104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0};
//#endif
						 
uint8_t Auto_Backlight = 0;
uint32_t Backlight_count = 0;
uint8_t Backlight_flag = 0;
uint8_t Backlight_touch = 0;

/*Variable space*/
//uint8_t var[VAR_SIZE] = {0};				    // variable buffer(reserved)
uint8_t *var = (uint8_t *)(0x1FFF8000);			// variable buffer
uint8_t var_temp[VAR_SIZE] = {0};				// variable buffer
uint8_t config_buff[PAGECFG_SIZE] = {0};		// variable buffer
uint8_t Display_buff[STRLEN_SIZE];				// display buffer
uint8_t Display_buff_temp[STRLEN_SIZE];			// display buffer
uint16_t Curve_buff[CURVE_CHANNEL][1024] = {0}; // Curve data buffer: 8 channels, 16KB in total
uint16_t Curve_count[CURVE_CHANNEL] = {0};		// Curve length
uint8_t curve_update_flag[CURVE_CHANNEL];		// Curve update flag
Curve_Info gCurve_Info[CURVE_SIZE];

/*data display*/
uint8_t data_D_num = 0;					 // width used to recorddata display
uint16_t data_D_w[DATA_WLEN_SIZE] = {0}; // width used to recorddata display
uint16_t data_w = 0;

/*picture data display*/
uint8_t pdata_D_num;					   // width used to record picture data display
uint16_t pdata_D_w[PDATA_WLEN_SIZE] = {0}; // width used to record picture data display

/*encoder*/
uint16_t gEncoder_addr[40] = {0};
uint16_t Check_box_add = 0xFFFF;
uint8_t Check_box_flag = 0;
uint8_t gEncoder_count = 0;
uint8_t gEncoder_num = 0;
uint8_t knob_flag = 0;
uint8_t gEncoderFlag = 0;

/*touch public*/
uint8_t button_Press_flag = 0; // other touch cannot act after the touch is pressed
uint8_t buzzer_start = 0;
uint8_t buzzer_10ms_count = 0;
uint8_t Button_Key_Code_Flag = 0;
uint16_t Button_Key_Code = 0;

/*basic touch*/
uint8_t Basci_count = 0;
uint8_t Basci_flag = 0;
uint8_t Basci_num = 0;
Basci_Info gBasci_Info[BASIC_SIZE];

/*variable adjustment*/
uint8_t Adj_count = 0;
uint8_t Adj_flag = 0;
uint8_t Adj_num = 0;
uint8_t Adj_time = 0;
uint8_t Adj_loop = 0;
bool Var_loop_flag = FALSE;
uint16_t Var_time = 0;
Adj_Info gAdj_Info[ADJUST_SIZE];

/*sliding progress bar*/
uint8_t Slide_count = 0;
uint8_t Slide_flag = 0;
uint8_t slide_first_touch = 0;
uint8_t slide_num = 0;
Slide_Info gSlide_Info[SLIDE_SIZE];

/*data keyboard*/
Dio_Info gDio_Info[DIO_SIZE];
uint8_t Dio_count = 0;
uint8_t Dio_num = 0;
uint8_t Dio_flag = 0;

/*keyboard keys*/
Kb_Info gKb_Info[KEYBOARD_SIZE];
uint8_t Kb_count = 0;
uint8_t Kb_num = 0;
uint8_t Kb_flag = 0;
uint8_t DioKb_flag = 0; // data input flag
uint8_t dot_flag;
uint8_t i_len = 0;
uint8_t d_len = 0;
uint16_t input_len = 0;
uint8_t neg_flag = 0;
uint16_t input_w = 0;
uint8_t cur_w = 0; // cursor width
uint16_t cur_x = 0;
uint16_t cur_y = 0;
uint16_t Cusor_time = 0; // cursor blink time
uint8_t Cusor_sw = 0;

/*sliding gesture*/
Gesture_Info gGesture_Info;

/*ASCII keyboard*/
Aio_Info gAio_Info[AIO_SIZE];
uint8_t Aio_count = 0;
uint8_t Aio_num = 0;
uint8_t Aio_flag = 0;
uint8_t AioKb_flag = 0;
uint8_t CapsLock = 0; // Caps lock

/*GBK keyboard*/
GBKio_Info gGBKio_Info[GBKIO_SIZE];
uint8_t GBKio_count = 0;
uint8_t GBKio_num = 0;
uint8_t GBKio_flag = 0;
uint8_t GBKioKb_flag = 0;
uint8_t GBK_PY_length = 0; // Pinyin length
uint8_t GBK_CN_EN = 0;	   // Chinese and English input method enable
uint8_t GBK_PY_buff[8] = {0};
uint16_t GBK_PY_num = 0;
uint8_t GBK_len = 0;
uint32_t GBK_PY_addr = 0;
uint8_t GBK_linenum = 0;

/*variable control of touch mode*/
uint8_t VarKey_count = 0;
uint8_t VarKey_flag = 0;
uint8_t VarKey_num = 0;
VarKey_Info gVarKey_Info[BATCH_SIZE];

/*pop-up window*/
uint8_t Pop_up_count = 0;
uint8_t Pop_up_flag = 0;
uint8_t Pop_up_num = 0;
uint8_t Pop_up_press = 0;
uint16_t Pop_up_x = 0;
uint16_t Pop_up_y = 0;
uint16_t Pop_up_id = 0;
Pop_up_Info gPop_up_Info[POPUP_SIZE];

uint8_t Ascii_w[95] = {0};

uint8_t Gif_num = 0;
uint8_t Gif_flag = 0;
Gif_Info gGif_Info[GIF_SIZE];

void jpg_decode_onFlash(void)
{
	
}
/********************************************************************************
 * Function Name : LT_ReceiveCmd
 * Description   : Instruction processing.
 * Input         : - buf: Buffer address of instruction
 * Output        : None
 * Return        : None
 *********************************************************************************/
void LT_ReceiveCmd(uint8_t *buf)
{
	uint8_t cmd = 0, temp = 0, num = 0, cnt = 0;
	uint8_t rebuf[260];
	uint16_t i = 0, j = 0;
	uint16_t rxCrc, mcuCrc;
	uint16_t addr = 0xFFFF, len = 0;

	gUsartRx.Flag = 0;
	cmd = buf[1];
	//printf("----------LT_ReceiveCmd %x %x %x %x %x\r\n",buf[0],buf[1],buf[2],buf[3],buf[4]);
	if (cmd == 0x03 || cmd == 0x10)
	{
		if (CRC_Enable_Flag)
		{
			rxCrc = buf[gUsartRx.Count - 1];
			rxCrc = (rxCrc << 8) + buf[gUsartRx.Count - 2];
			mcuCrc = CRC16(&buf[1], gUsartRx.Count - 3);
		}
		else
			rxCrc = mcuCrc;

		if (rxCrc == mcuCrc) // CRC OK
		{
			if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
			{
				rebuf[3] = cmd;
				rebuf[4] = 0xFF;
				LT_SendData_CRC_Frame(rebuf, 2);
			}

			/***************************Read instruction***************************/
			if (cmd == 0x03)
			{
				addr = (buf[2] << 8) | buf[3];
				len = (buf[4] << 8) | buf[5];
				
				Var_AddrRemapping(&addr);

				for (i = 0; i < 5; i++)
				{
					rebuf[3 + i] = buf[1 + i];
				}

				if (addr < VAR_ADDR_S) // Variable address
				{
					for (i = 0; i < len; i++)
					{
						rebuf[8 + 2 * i] = var[2 * (addr + i)];
						rebuf[9 + 2 * i] = var[2 * (addr + i) + 1];
					}
				}
				else if (addr >= VAR_ADDR_S && addr <= VAR_ADDR_E)
				{

					if (addr + len >= VAR_TIME || addr <= (VAR_TIME + 5))
					{
						var[VAR_TIME * 2 + 1] = calendar.w_year - 2000;
						var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
						var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
						var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
						var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
						var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
					}
					for (i = 0; i < len; i++)
					{
						rebuf[8 + 2 * i] = var[2 * (addr + i)];
						rebuf[9 + 2 * i] = var[2 * (addr + i) + 1];
					}
				}

				LT_SendData_CRC_Frame(rebuf, 5 + len * 2);
			}
			/***************************Write instructions***************************/
			else if (cmd == 0x10)
			{
				addr = (buf[2] << 8) | buf[3];
				if (CRC_Enable_Flag)
					len = (buf[0] - 2 - 3) / 2;
				else
					len = (buf[0] - 3) / 2;
				
				Var_AddrRemapping(&addr);

				if (addr < VAR_ADDR_S) // Variable address
				{
					// save data
					for (i = 0; i < len; i++)
					{
						var[2 * (addr + i)] = buf[4 + 2 * i];
						var[2 * (addr + i) + 1] = buf[5 + 2 * i];
					}
				}
				else if (addr >= VAR_ADDR_S && addr <= VAR_ADDR_E)
				{

					for (i = 0; i < len; i++)
					{
						var[2 * (addr + i)] = buf[4 + 2 * i];
						var[2 * (addr + i) + 1] = buf[5 + 2 * i];
					}

					for (i = 0; i < len;)
					{
						if ((addr + i) == VAR_PAGE) // page
						{
							if (pic_id != (var[VAR_PAGE * 2] << 8 | var[VAR_PAGE * 2 + 1]))
							{
								Display_page(var[VAR_PAGE * 2] << 8 | var[VAR_PAGE * 2 + 1]);
							}
							i++;
						}
						else if ((addr + i) == VAR_BL) // backlight
						{
							if (var[VAR_BL * 2 + 1] > 63)
								var[VAR_BL * 2 + 1] = 63;

							LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
							Backlight_flag = 1;
							
							i++;
						}
						else if ((addr + i) == VAR_TIME) // time
						{
							if (var[VAR_TIME * 2 + 1] > 99)
								var[VAR_TIME * 2 + 1] = 99;
							if (var[(VAR_TIME + 1) * 2 + 1] > 12)
								var[(VAR_TIME + 1) * 2 + 1] = 12;
							if (var[(VAR_TIME + 2) * 2 + 1] > 31)
								var[(VAR_TIME + 2) * 2 + 1] = 31;
							if (var[(VAR_TIME + 3) * 2 + 1] > 23)
								var[(VAR_TIME + 3) * 2 + 1] = 23;
							if (var[(VAR_TIME + 4) * 2 + 1] > 59)
								var[(VAR_TIME + 4) * 2 + 1] = 59;
							if (var[(VAR_TIME + 5) * 2 + 1] > 59)
								var[(VAR_TIME + 5) * 2 + 1] = 59;

							RTC_Set(2000 + var[VAR_TIME * 2 + 1], var[(VAR_TIME + 1) * 2 + 1], var[(VAR_TIME + 2) * 2 + 1], var[(VAR_TIME + 3) * 2 + 1], var[(VAR_TIME + 4) * 2 + 1], var[(VAR_TIME + 5) * 2 + 1]);
							i += 6;
						}
						else if ((addr + i) == VAR_TIMESET) // time setting
						{
							i++;
						}
						else if ((addr + i) == VAR_RSIZE_9) // NULL
						{
							i++;
						}
						else if ((addr + i) == VAR_WAV) // WAV
						{
							Wav_DAC_Init((var[VAR_WAV * 2] << 8) | var[VAR_WAV * 2 + 1]);
							i++;
						}
						else if ((addr + i) == VAR_VOLUME) // sound volume
						{
							if (var[2 * VAR_VOLUME + 1] > 16)
								wav_reduce_para = 16;
							else
								wav_reduce_para = var[2 * VAR_VOLUME + 1];
							i++;
						}
						else if ((addr + i) == VAR_RTP) // RTP calibration
						{
							if (var[VAR_RTP * 2 + 1] == 0x5A)
							{
#if (LT_TOUCH_FLAG == 1)
								LT_TpAdjust();
#endif
								var[VAR_RTP * 2 + 1] = 0x00;
								Display_page(((var[VAR_PAGE * 2] << 8) | var[VAR_PAGE * 2 + 1]));
							}
							i++;
						}
						else if ((addr + i) == VAR_KEY) // Key code trigger
						{
							Button_Key_Code = (var[VAR_KEY * 2] << 8) | var[VAR_KEY * 2 + 1];
							Button_Key_Code_Flag = 1;
							i++;
						}
						else if ((addr + i) == VAR_BLAUTO)
						{
							if(var[2 * VAR_BLAUTO + 1] == 1)
							{
								if (Backlight_flag == 0)
								{	
									Backlight_count = 0;								
									Backlight_flag = 1;
									LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
								}
							}
							else if (var[2 * VAR_BLAUTO + 1] == 0)
							{
								Backlight_count = 0;								
								Backlight_flag = 0;
								LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
							}
							i++;
						}
						else if ((addr + i) == VAR_BLSLEEP)
						{
							if (Backlight_flag == 0 && var[2 * VAR_BLAUTO + 1] == 1)
							{
								LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);
							}
							i++;
						}
						else
						{
							i++;
						}
					}
				}
				else if (addr >= VAR_CURVE_WS && addr <= VAR_CURVE_WE) // Curve channel address for write
				{
					temp = addr & 0xFFF;
					for (i = 0; i < CURVE_CHANNEL; i++)
					{
						if (temp & (1 << i))
							num++; // Record the number of channel groups
					}

					i = 0;
					j = 0;
					while (j < len) // Store data to corresponding channels respectively
					{
						if (temp & (1 << i))
						{
							Curve_buff[i][Curve_count[i]] = buf[4 + 2 * j] << 8 | buf[5 + 2 * j];
							Curve_count[i]++;
							if (Curve_count[i] >= 1024)
							{
								Curve_count[i] = 0;
							}
							curve_update_flag[i] = 1;
							j++;
						}
						i++;
						if (i >= CURVE_CHANNEL)
							i = 0;
					}

					if (len % num) // When multi-channel buffer data is triggered, if some channel data is missing, the missing part will be supplemented
					{
						for (i = 0; i < CURVE_CHANNEL; i++)
						{
							if (temp & (1 << i))
								cnt++;
							if (cnt > len % num && (temp & (1 << i)))
							{
								if (Curve_count[i] != 0)
									Curve_buff[i][Curve_count[i]] = Curve_buff[i][Curve_count[i] - 1];
								else
									Curve_buff[i][0] = Curve_buff[i][1023];

								Curve_count[i]++;
								if (Curve_count[i] >= 1024)
								{
									Curve_count[i] = 0;
								}
							}
						}
					}
				}
				else if (addr >= VAR_CURVE_CS && addr <= VAR_CURVE_CE) // Curve channel address for clear
				{
					temp = addr & 0xFFF;

					i = 0;
					j = 0;
					for (i = 0; i < CURVE_CHANNEL; i++) // clear data
					{
						if (temp & (1 << i))
						{
							for (j = 0; j < 1024; j++)
							{
								Curve_buff[i][j] = 0x00;
							}

							Curve_count[i] = 0;
							curve_update_flag[i] = 1;
						}
					}
				}
			}
		}
		else // CRC NG
		{
			if (CRC_Feedback_Flag) // CRC feedback is the default
			{
				rebuf[3] = cmd;
				rebuf[4] = 0x00;
				LT_SendData_CRC_Frame(rebuf, 2);
			}
		}
	}
	else if (cmd == 0x61 || cmd == 0x62 || cmd == 0x65 || cmd == 0x66)
	{
		U_UpdateCMDanalyse(cmd, buf);
	}

	gUsartRx.Flag = 0;
	gUsartRx.Count = 0; // Clear to receive the next data
	LT_ClearRxBuf();	// Clear receive buffer
}

#if (UARTBUS_OPTION == 1) || (UARTBUS_OPTION == 2)
void LT_ModBus_REG_Cmd(void)
{
	uint16_t i = 0;
	for (i = 0; i < 20;)
	{
		if (i == 0 && flag_MB_REG[i])
		{
			if (pic_id != (var[2 * VAR_PAGE] << 8 | var[2 * VAR_PAGE + 1]))
			{
				Display_page(var[2 * VAR_PAGE] << 8 | var[2 * VAR_PAGE + 1]);
			}
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 1 && flag_MB_REG[i])
		{
			if (var[VAR_BL * 2 + 1] > 63)
				var[VAR_BL * 2 + 1] = 63;

			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			Backlight_flag = 1;

			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 2 && flag_MB_REG[i]) // time
		{
			if (var[VAR_TIME * 2 + 1] > 99)
				var[VAR_TIME * 2 + 1] = 99;
			if (var[(VAR_TIME + 1) * 2 + 1] > 12)
				var[(VAR_TIME + 1) * 2 + 1] = 12;
			if (var[(VAR_TIME + 2) * 2 + 1] > 31)
				var[(VAR_TIME + 2) * 2 + 1] = 31;
			if (var[(VAR_TIME + 3) * 2 + 1] > 23)
				var[(VAR_TIME + 3) * 2 + 1] = 23;
			if (var[(VAR_TIME + 4) * 2 + 1] > 59)
				var[(VAR_TIME + 4) * 2 + 1] = 59;
			if (var[(VAR_TIME + 5) * 2 + 1] > 59)
				var[(VAR_TIME + 5) * 2 + 1] = 59;

			RTC_Set(2000 + var[(VAR_TIME + 0) * 2 + 1], var[(VAR_TIME + 1) * 2 + 1], var[(VAR_TIME + 2) * 2 + 1], var[(VAR_TIME + 3) * 2 + 1], var[(VAR_TIME + 4) * 2 + 1], var[(VAR_TIME + 5) * 2 + 1]);
			flag_MB_REG[i] = 0;
			i += 6;
		}
		else if (i == 8 && flag_MB_REG[i] == 1) // time setting
		{
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 9 && flag_MB_REG[i] == 1) // NULL
		{
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 10 && flag_MB_REG[i] == 1) // WAV
		{
			Wav_DAC_Init((var[VAR_WAV * 2] << 8) | var[VAR_WAV * 2 + 1]);
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 11 && flag_MB_REG[i] == 1) // sound volume
		{
			if (var[2 * VAR_VOLUME + 1] > 16)
				wav_reduce_para = 16;
			else
				wav_reduce_para = var[2 * VAR_VOLUME + 1];
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 12 && flag_MB_REG[i] == 1) // RTP calibration
		{
			if (var[VAR_RTP * 2 + 1] == 0x5A)
			{
#if (LT_TOUCH_FLAG == 1)
				LT_TpAdjust();
#endif
				var[VAR_RTP * 2 + 1] = 0x00;
				Display_page(((var[VAR_PAGE * 2] << 8) | var[VAR_PAGE * 2 + 1]));
			}
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 13 && flag_MB_REG[i] == 1) // Key code trigger
		{
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 14 && flag_MB_REG[i] == 1)
		{
			if(var[2 * VAR_BLAUTO + 1] == 1)
			{
				if (Backlight_flag == 0)
				{	
					Backlight_count = 0;								
					Backlight_flag = 1;
					LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
				}
			}
			else if (var[2 * VAR_BLAUTO + 1] == 0)
			{
				Backlight_count = 0;								
				Backlight_flag = 0;
				LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			}
			i++;	
		}
		else if (i == 15 && flag_MB_REG[i] == 1)
		{
			if (Backlight_flag == 0 && var[2 * VAR_BLAUTO + 1] == 1)
			{
				LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);
			}
			i++;
		}
		else
		{
			i++;
		}
	}
}

#endif

#if IIC_BUS
void LT_IIC_REG_Cmd(void)
{
	uint16_t i = 0;
	for (i = 0; i < 20;)
	{
		if (i == 0 && flag_IIC_REG[i] == 1)
		{
			Display_page(var[VAR_PAGE * 2] << 8 | var[VAR_PAGE * 2 + 1]);
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 1 && flag_IIC_REG[i] == 1)
		{
			if (var[VAR_BL * 2 + 1] > 63)
				var[VAR_BL * 2 + 1] = 63;

			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			Backlight_flag = 1;


			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 2 && flag_IIC_REG[i] == 1)
		{
			if (var[(VAR_TIME + 0) * 2 + 1] > 99)
				var[(VAR_TIME + 0) * 2 + 1] = 99;
			if (var[(VAR_TIME + 1) * 2 + 1] > 12)
				var[(VAR_TIME + 1) * 2 + 1] = 12;
			if (var[(VAR_TIME + 2) * 2 + 1] > 31)
				var[(VAR_TIME + 2) * 2 + 1] = 31;
			if (var[(VAR_TIME + 3) * 2 + 1] > 23)
				var[(VAR_TIME + 3) * 2 + 1] = 23;
			if (var[(VAR_TIME + 4) * 2 + 1] > 59)
				var[(VAR_TIME + 4) * 2 + 1] = 59;
			if (var[(VAR_TIME + 5) * 2 + 1] > 59)
				var[(VAR_TIME + 5) * 2 + 1] = 59;

			RTC_Set(2000 + var[(VAR_TIME + 0) * 2 + 1], var[(VAR_TIME + 1) * 2 + 1], var[(VAR_TIME + 2) * 2 + 1], var[(VAR_TIME + 3) * 2 + 1], var[(VAR_TIME + 4) * 2 + 1], var[(VAR_TIME + 5) * 2 + 1]);
			flag_IIC_REG[i] = 0;
			i += 6;
		}
		else if (i == 8 && flag_IIC_REG[i] == 1)
		{
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 9 && flag_IIC_REG[i] == 1)
		{
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 10 && flag_IIC_REG[i] == 1)
		{
			var[VAR_WAV * 2] = ID_IIC_WAV >> 8;
			var[VAR_WAV * 2 + 1] = ID_IIC_WAV & 0xFF;

			Wav_DAC_Init((var[VAR_WAV * 2] << 8) | var[VAR_WAV * 2 + 1]);
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 11 && flag_IIC_REG[i] == 1)
		{
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 12 && flag_IIC_REG[i] == 1)
		{
			if (var[VAR_RTP * 2 + 1] == 0x5A)
			{
#if (LT_TOUCH_FLAG == 1)
				LT_TpAdjust();
#endif
				var[VAR_RTP * 2 + 1] = 0x00;
				Display_page(((var[VAR_PAGE * 2] << 8) | var[VAR_PAGE * 2 + 1]));
			}
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 13 && flag_IIC_REG[i] == 1)
		{
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 14 && flag_IIC_REG[i] == 1)
		{
			if(var[2 * VAR_BLAUTO + 1] == 1)
			{
				if (Backlight_flag == 0)
				{	
					Backlight_count = 0;								
					Backlight_flag = 1;
					LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
				}
			}
			else if (var[2 * VAR_BLAUTO + 1] == 0)
			{
				Backlight_count = 0;								
				Backlight_flag = 0;
				LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			}
			i++;
		}
		else if (i == 15 && flag_IIC_REG[i] == 1)
		{
			if (Backlight_flag == 0 && var[2 * VAR_BLAUTO + 1] == 1)
			{
				LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);
			}
			i++;
		}
		else
		{
			i++;
		}
	}
}
#endif

void Var_AddrRemapping(uint16_t *addr)
{
#if (VAR_REG_S == 0x7000)
	if (*addr >= VAR_REG_S && *addr <= VAR_REG_E)
		*addr -= 0x5000;
#endif
//	if (*addr > (VAR_ADDR_E + 0xFF))
//		*addr = 0;
//	;
}

/********************************************************************************
 * Function Name : reg_operation
 * Description   : Operation register.
 * Input         : - addr: register address
 * Output        : None
 * Return        : None
 *********************************************************************************/
void reg_operation(uint16_t addr)
{
	if (addr == VAR_PAGE)
	{
		if (pic_id != (var[VAR_PAGE * 2] << 8) + var[VAR_PAGE * 2 + 1])
		{
			Display_page((var[VAR_PAGE * 2] << 8) + var[VAR_PAGE * 2 + 1]);
		}
	}
	else if (addr == VAR_BL)
	{
		if (var[VAR_BL * 2 + 1] > 63)
			var[VAR_BL * 2 + 1] = 63;

		LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		Backlight_flag = 1;
//		if (Auto_Backlight)
//		{
//			Backlight_count = 0;
//			Backlight_flag = 1;
//		}
	}
	else if (addr == VAR_TIMESET) // time setting
	{
		RTC_Get();

		if (var[VAR_TIMESET * 2 + 1] == 1)
		{
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
			var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 2)
		{
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
			var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 3)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
			var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 4)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 5)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 6)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
		}

		RTC_Set(2000 + var[(VAR_TIME + 0) * 2 + 1], var[(VAR_TIME + 1) * 2 + 1], var[(VAR_TIME + 2) * 2 + 1], var[(VAR_TIME + 3) * 2 + 1], var[(VAR_TIME + 4) * 2 + 1], var[(VAR_TIME + 5) * 2 + 1]);
	}
	else if (addr == VAR_WAV)
	{
		Wav_DAC_Init((var[VAR_WAV * 2] << 8) + var[VAR_WAV * 2 + 1]);
	}
	else if (addr == VAR_VOLUME)
	{
		if (var[2 * VAR_VOLUME + 1] > 16)
			wav_reduce_para = 16;
		else
			wav_reduce_para = var[2 * VAR_VOLUME + 1];
	}
	else if (addr == VAR_BLAUTO)
	{
		if(var[2 * VAR_BLAUTO + 1] == 1)
		{
			if (Backlight_flag == 0)
			{	
				Backlight_count = 0;								
				Backlight_flag = 1;
				LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			}
		}
		else if (var[2 * VAR_BLAUTO + 1] == 0)
		{
			Backlight_count = 0;								
			Backlight_flag = 0;
			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		}
	}
	else if (addr == VAR_BLSLEEP)
	{
//		if (Backlight_flag == 0 && var[2 * VAR_BLAUTO + 1] == 1)
//		{
//			LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);
//		}
	}
}
uint8_t page_buff_flag = 0;
/***********************************************************************************
 * Function Name : Display_page
 * Description   : Display the interface of a page.
 * Input         : - id: Page No
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Display_page(uint16_t id)
{

	if (id <= addr_index[7])
	{
		uint8_t buff[12] = {0};

		var[VAR_PAGE * 2 + 0] = id >> 8;
		var[VAR_PAGE * 2 + 1] = id & 0xFF;

		LT_ReadFlash(buff, addr_index[6] + 12 * id, 12);
		pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		pic_w = buff[4] + (buff[5] << 8);
		pic_h = buff[6] + (buff[7] << 8);
		pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		pic_flag = buff[11];
		pic_id = id;

		FullScreen_addr = pic_add;
		FullScreen_color = pic_len;
		FullScreen_flag = pic_flag;

		// debug
		printf("page id: %d  \r\n", id);
		//		 printf("page id: %d , page info: %d  %d  %d   %d  0x%x     \r\n",id,pic_w,pic_h,pic_len,pic_flag,pic_add);

		/*Clear previous page key function*/
		Button_Key_Code_Flag = 0;
		Button_Key_Code = 0;

		Basci_count = 0;
		Basci_flag = 0;
		//		Ges_sc_flag = 0;
		Adj_count = 0;
		Adj_flag = 0;

		Slide_count = 0;
		Slide_flag = 0;

		Dio_count = 0;
		Dio_flag = 0;
		DioKb_flag = 0;
		Aio_count = 0;
		AioKb_flag = 0;
		Aio_flag = 0;
		GBKio_count = 0;
		GBKioKb_flag = 0;
		GBKio_flag = 0;
		Kb_count = 0;
		Kb_flag = 0;

		sldmenu_count = 0;
		sldmenu_flag = 0;

		VarKey_count = 0;
		VarKey_flag = 0;

		Pop_up_count = 0;
		Pop_up_flag = 0;
		button_Press_flag = 0;
		/**************/

		/*Clear the dynamic display function on the previous page*/
		data_D_num = 0;
		memset(data_D_w, 0, sizeof(data_D_w));

		pdata_D_num = 0;
		memset(pdata_D_w, 0, sizeof(pdata_D_w));
		Gif_num = 0;
		RTC_num = 0;
		Clock_num = 0;
		Scroll_num = 0;
		Gesture_flag = 0;
		RingSld_count = 0;
		curve_num = 0;
		gEncoderFlag = 0;

		Saving_counting_parameters(); // Save data for time counter
		Count_sum = 0;

#if (UARTBUS_OPTION == 2)
		if (gUsartTx.Mode == 0x02)
			tx_repeat_flag = 0;
#endif
		// LT268_TFT_ShowPicture(0, 0, pic_w, pic_h, pic_add);
		if (gWavFlag == 1 || gWavType == 1)
		{
			gWavType = 0;
			close_wav_dac();
		}

		RTC_Get();
		var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
		var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
		var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
		var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
		var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
		var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		var[VAR_TIMESET * 2 + 1] = calendar.week;

		if (pic_flag == 0x10) // pure color
		{
			LT268_TFT_FillColor(0, 0, LCD_XSIZE_TFT, LCD_YSIZE_TFT, pic_len);
		}
		else if (pic_id == 10)
		{
			page_buff_flag = 0;
			LT268_TFT_ShowPicture(0, 0, pic_w, pic_h, pic_add); // OPEN
			Get_date_variable_Id(id);
			Get_Touch_info(id);
		}
		else // picture
		{
			page_buff_flag = 1;

			LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
								0, 0, pic_w, pic_add,
								pic_w, pic_h, pic_flag);

			if (Long_press_lock == 1)
			{
				var[0x0288 * 2 + 1] = 1;
			}
			if (Long_press_lock == 0)
			{
				var[0x0288 * 2 + 1] = 0;
			}

			if (pic_id == 2 || pic_id == 3 || pic_id == 4 || pic_id == 5 || pic_id == 6 || pic_id == 9 || pic_id == 10 ||
				pic_id == 11 || pic_id == 12 || pic_id == 13 || pic_id == 14 || pic_id == 15 || pic_id == 16 || pic_id == 17 || pic_id == 18 || pic_id == 19 || pic_id == 20 || pic_id == 21 || pic_id == 22 || pic_id == 23 || pic_id == 24 || pic_id == 25 || pic_id == 26 || pic_id == 37 || pic_id == 41 || pic_id == 42 || pic_id == 43 || pic_id == 7 || pic_id == 0)
			{
				// pic_w=240;pic_h=320;//CJ
				// LT268_buffer_to_TFT(0, 0, pic_w, m_PngData,
				// 					0, 0, pic_w, pic_h);
			}
			// LT268_TFT_ShowPicture(0, 0, pic_w, pic_h, pic_add);//OPEN


			if (pic_id == 27)
			{
				var[0x0201 * 2] = (Mode_I_Sum >> 8) & 0xff;
				var[0x0201 * 2 + 1] = Mode_I_Sum & 0xff;
			}
			else if (pic_id == 29)
			{
				var[0x0211 * 2] = (Mode_II_Sum >> 8) & 0xff;
				var[0x0211 * 2 + 1] = Mode_II_Sum & 0xff;
			}
			else if (pic_id == 31)
			{
				var[0x0221 * 2] = (Mode_III_Sum >> 8) & 0xff;
				var[0x0221 * 2 + 1] = Mode_III_Sum & 0xff;
			}

			Get_date_variable_Id(id);
			Get_Touch_info(id);

			pic_w = 240;
			pic_h = 320; // CLOSE
			LT268_buffer_to_TFT(0, 0, pic_w, m_PngData,
								0, 0, pic_w, pic_h);

			page_buff_flag = 0;
		}
	}
}

/***********************************************************************************
* Function Name : Display_pop_up
* Description   : Show pop-up page.
* Input         : - id: page id
				  - x,y: Screen coordinates
* Output        : None
* Return        : None
************************************************************************************/
void Display_pop_up(uint16_t id, uint16_t x, uint16_t y)
{
	if (id <= addr_index[7])
	{
		uint8_t buff[12] = {0};
		uint16_t w, h;
		uint8_t bgflag = 0;

		LT_ReadFlash(buff, addr_index[6] + 12 * id, 12);
		pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		pic_w = buff[4] + (buff[5] << 8);
		pic_h = buff[6] + (buff[7] << 8);
		pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		pic_flag = buff[11];
		pic_id = id;
		w = pic_w;
		h = pic_h;

		// debug
//		printf("Display_pop_up: xy %d  %d   wh %d  %d  %d   %d  0x%x     \r\n",x,y,pic_w,pic_h,pic_len,pic_flag,pic_add);

		Page_VirAddr = pic_add;
		Page_VirLen = pic_len;
		Page_VirFlag = 0;
		Page_VirW = pic_w;
		Page_VirH = pic_h;

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			if ((gPop_up_Info[Pop_up_num].function & 0x01) == 1) // bokeh background
			{
				bgflag = 1;
			}
			if (pic_flag == 0)
				LT268_TFT_ShowPicture(x, y, pic_w, pic_h, pic_add);
			else if (pic_flag == 1)
				LT268_TFT_ShowPicture_Png(x, y, pic_w, pic_h, pic_add);
			else if (pic_flag == 1)
				LT268_TFT_ShowPicture_Png_Pixel(x, y, pic_w, pic_h, pic_add);
		}

		/*clear page*/
		Button_Key_Code_Flag = 0; // Key code clearing
		Button_Key_Code = 0;
		Basci_count = 0;
		Basci_flag = 0;
		// Ges_sc_flag = 0;
		Adj_count = 0;
		Adj_flag = 0;
		Slide_count = 0;
		Slide_flag = 0;
		Dio_count = 0;
		Dio_flag = 0;
		DioKb_flag = 0;
		Aio_count = 0;
		AioKb_flag = 0;
		Aio_flag = 0;
		GBKio_count = 0;
		GBKioKb_flag = 0;
		GBKio_flag = 0;
		Kb_count = 0;
		Kb_flag = 0;
		Kb_count = 0;
		Kb_flag = 0;
		sldmenu_count = 0;
		sldmenu_flag = 0;
		VarKey_count = 0;
		VarKey_flag = 0;
		// Pop_up_count = 0;		//Pop-up coordinate offset needs to be used and cannot be shielded
		// Pop_up_flag = 1;
		button_Press_flag = 0;
		data_D_num = 0;
		pdata_D_num = 0;
		memset(data_D_w, 0, sizeof(data_D_w));

		Gif_num = 0;
		RTC_num = 0;
		Clock_num = 0;
		Scroll_num = 0;
		Gesture_flag = 0;
		RingSld_count = 0;
		Saving_counting_parameters();
		Count_sum = 0;
		gWavType = 0;

#if (UARTBUS_OPTION == 2)
		if (gUsartTx.Mode == 0x02)
			tx_repeat_flag = 0;
#endif

		RTC_Get();
		var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
		var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
		var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
		var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
		var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
		var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		var[VAR_TIMESET * 2 + 1] = calendar.week;

		Get_date_variable_Id(id);
		Get_Touch_info(id);
		Wav_DAC_Init((var[VAR_WAV * 2] << 8) + var[VAR_WAV * 2 + 1]);
	}
}

/***********************************************************************************
* Function Name	: Display_Icon
* Description	: Show a icon.
* Input			: - id: icon id
				  - x,y: Screen coordinates
* Output        : None
* Return        : None
************************************************************************************/
void Display_Icon(uint16_t id, uint16_t x, uint16_t y, uint8_t Display_mode)
{
	uint8_t buff[12] = {0};
	uint8_t Ebuff[1] = {0};
	LT_ReadFlash(buff, addr_index[10] + 12 * id, 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	pic_w = buff[4] + (buff[5] << 8);
	pic_h = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];
	if(Display_mode)
		IconBG_Flag = 1;
	// printf("pic_add=0x%x  pic_w=%d pic_h=%d pic_flag=%d x=%d y=%d \r\n",pic_add,pic_w,pic_h,pic_flag,x,y);
	// printf("Display_Icon  %d  %d  %d  %d  x%x  %d \r\n",x,y,pic_w,pic_h,pic_add,pic_flag,Display_mode);
	if (pic_len != 0 && pic_flag != 0xFF)
	{
		if (pic_flag == 0)
		{
			LT268_TFT_ShowPicture(x, y, pic_w, pic_h, pic_add);
		}
		else if (pic_flag == 1)
		{
			LT268_TFT_ShowPicture_Png(x, y, pic_w, pic_h, pic_add);
		}
		else if (pic_flag == 2)
		{
			if (Check_box_flag == 0 || Check_box_flag == 1 || Check_box_flag == 2)
			{
				LT268_TFT_ShowPicture_Png_Pixel(x, y, pic_w, pic_h, pic_add);
			}
			else if (Check_box_flag == 3)
			{
				LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
									0, 0, pic_w, pic_add,
									pic_w, pic_h, pic_flag);
				LT268_buffer_to_TFT(0, 0, pic_w, m_PngData,
									x, y, pic_w, pic_h);
			}

		}
		else if (pic_flag == 3 || pic_flag == 4 || pic_flag == 5)
		{
			LT268_TFT_ShowPicture_zip(x, y, pic_w, pic_h, pic_add);
		}

	}

}
/***********************************************************************************
* Function Name : icon_display
* Description   : Show a icon.
* Input         : - type: icon info sources
				  - buff: icon info
* Output        : None
* Return        : None
************************************************************************************/
void icon_display(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, p_len, pointer;
	uint16_t x, y, w, h;
	uint16_t simage, eimage, nimage;
	uint16_t s_num, e_num;
	uint16_t d_num;
	uint8_t buff1[12] = {0}, i;
	uint8_t Display_Mode = 0;

	if (type == 0) // instruction information source is configuration file
	{
		Display_Mode = (buff[4] & 0x80) >> 7;
		p_add = (buff[5] + (buff[6] << 8));
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		simage = buff[11] + (buff[12] << 8);
		eimage = buff[13] + (buff[14] << 8);
		s_num = buff[15] + (buff[16] << 8);
		e_num = buff[17] + (buff[18] << 8);
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (buff[pointer] + (buff[pointer + 1] << 8));
		x = buff[pointer + 2] + (buff[pointer + 3] << 8);
		y = buff[pointer + 4] + (buff[pointer + 5] << 8);
		simage = buff[pointer + 6] + (buff[pointer + 7] << 8);
		eimage = buff[pointer + 8] + (buff[pointer + 9] << 8);
		s_num = buff[pointer + 10] + (buff[pointer + 11] << 8);
		e_num = buff[pointer + 12] + (buff[pointer + 13] << 8);
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}
	
	if(p_add==0x1960)
	{
		uint8_t PWflag;
		PWflag = IO_READ8(Password_Flag_sAddr);	//读回密码设置状态	
		if(PWflag>1)
		{
			PWflag = 0;
			EFLASH_Init(g_sys_clk / 1000);
			EFLASH_SetWritePermission();
			W_buff[13] = PWflag;
			EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
			EFLASH_ClrWritePermission();
		}
		if(PWflag==0)	 var[p_add * 2 + 1]=1;
		else	var[p_add * 2 + 1]=2;
	}
	if(Lock_flag)
	{
		if(p_add==0x1025)	var[p_add * 2 + 1] = IO_READ8(Lock_mode1_sAddr);
		if(p_add==0x1026)	var[p_add * 2 + 1] = IO_READ8(Lock_mode2_sAddr);
		if(p_add==0x1027)	var[p_add * 2 + 1] = IO_READ8(Lock_mode3_sAddr);
		if(p_add==0x1028)	var[p_add * 2 + 1] = IO_READ8(Lock_mode4_sAddr);	
	}
	else
	{
		if(p_add==0x1025)	var[p_add * 2 + 1] = 0;
		if(p_add==0x1026)	var[p_add * 2 + 1] = 0;
		if(p_add==0x1027)	var[p_add * 2 + 1] = 0;
	    if(p_add==0x1028)	var[p_add * 2 + 1] = 0;	
	}

	nimage = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
	// printf("ICON p_add,nimage=0x%x   =%d   =%d \r\n",p_add,nimage,page_buff_flag);

	if(!page_buff_flag)
	{
		if (nimage >= s_num && nimage <= e_num)
		{
			d_num = simage + nimage - s_num;
			Display_Icon(d_num, x, y, Display_Mode);
		}
		else
		{
	//		if((p_add==0x1201||p_add==0x1202||p_add==0x1203||p_add==0x1204))
	//		{
	//		}
	//		else
	//		{
				LT_ReadFlash(buff1, addr_index[10] + 12 * simage, 12);
				pic_w = buff1[4] + (buff1[5] << 8);
				pic_h = buff1[6] + (buff1[7] << 8);
				LT268_dispaly_CutPicture(x, y,
										x, y, pic_w, pic_h,
										LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
	//		}

		}
	}
	else
	{
		if (nimage >= s_num && nimage <= e_num)
		{
			d_num = simage + nimage - s_num;
			//Display_Icon(d_num, x, y, Display_Mode);
			uint8_t buff[12] = {0};
			LT_ReadFlash(buff, addr_index[10] + 12 * d_num, 12);
			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];
			LT268_pic_to_buffer(x, y, LCD_XSIZE_TFT, m_PngData,
				0, 0, pic_w, pic_add,
				pic_w, pic_h, pic_flag);
		}
		else
		{
			uint8_t buff[12] = {0};
			LT_ReadFlash(buff, addr_index[10] + 12 * simage, 12);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);

			LT268_pic_to_buffer(x, y, LCD_XSIZE_TFT, m_PngData,
				x, y, LCD_XSIZE_TFT, FullScreen_addr,
				pic_w, pic_h, FullScreen_flag);
		}

	}

}	


/***********************************************************************************
* Function Name : bit_control
* Description   : control variable's bit.
* Input			: - type: icon info sources
				  - buff: icon info
* Output        : None
* Return        : None
************************************************************************************/
void bit_control(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, pointer;
	uint16_t x, y;
	uint16_t simage, eimage, nimage;
	uint8_t control_bit, Display_mode;
	uint8_t buff1[12] = {0};

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8));
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		control_bit = buff[11];
		simage = buff[12] + (buff[13] << 8);
		eimage = buff[14] + (buff[15] << 8);
		Display_mode = buff[16];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (buff[pointer] + (buff[pointer + 1] << 8));
		x = buff[pointer + 2] + (buff[pointer + 3] << 8);
		y = buff[pointer + 4] + (buff[pointer + 5] << 8);
		control_bit = buff[pointer + 6];
		simage = buff[pointer + 7] + (buff[pointer + 8] << 8);
		eimage = buff[pointer + 9] + (buff[pointer + 10] << 8);
		Display_mode = buff[pointer + 11];
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}

	nimage = (var[p_add * 2] << 8) + var[p_add * 2 + 1];

	if ((nimage & (0x01 << control_bit)) == 0)
	{
		Display_Icon(simage, x, y, 0);
	}
	else
	{
		Display_Icon(eimage, x, y, 0);
	}
}

/*******************************************************************************
 * Function Name : LT_Print_zk_Font
 * Description   : Display a string.
 * Input         :
 * Output        : None
 * Return        : None
 ********************************************************************/
uint16_t LT_Print_zk_Font(
	uint16_t encode // encoding type, 0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size // font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	,
	uint8_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	,
	_PICINFO mixpic // mix picture info
	,
	uint8_t text_mode // text display mode: 0:txt  1:encryption use '*' (0x2A)
	,
	uint16_t Xs // Text box start x position
	,
	uint16_t Ys // Text box start Y position
	,
	uint16_t Xe // Text box end x position
	,
	uint16_t Ye // Text box end y position
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
)
{
	uint32_t i = 0, j = 0;
	uint16_t X_start = 0, Y_start = 0;
	uint16_t box_w = Xe - Xs + 1, box_h = Ye - Ys + 1;
	uint8_t gray, gray_bit;
	uint16_t row = 0, row_num = 0, row_w[100]; // max line = 100
	uint16_t disp_w = 0, disp_i = 0,temp_w;
	uint8_t unicode_w;
	uint8_t font_flag=1;	//当不是密码键盘时为1
	uint16_t font_byte; // bytes of a single font

	LT_ReadFlash(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash(&gray, FlashAddr + 8, 1);

	if (W_Size == 30 && H_Size == 40) font_flag = 0;
	if (font_flag) Ascii_w[17] = 10;
	
	if (gray == 0)
		gray_bit = 1;
	else if (gray == 1)
		gray_bit = 2;
	else if (gray == 2)
		gray_bit = 4;
	font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;
	if (encode == 4) // ASCII
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = (Ascii_w[c[i] - 0x20] + dis_x + 2);
			else if (c[i] == 0x0A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				disp_w = 0;
				row_w[row_num++] = disp_w;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
				{
					i++;
					j++;
				}
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				j++;
			}
		}
	}
	else if (encode == 0) // GB2312
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
				{
					i++;
					j++;
				}
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				j++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
				j++;
			}
		}
	}
	else if (encode == 1) // GBK
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > (Xe - Xs + 1) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
				{
					i++;
					j++;
				}
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				j++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
				j++;
			}
		}
	}
	else if (encode == 2) // BIG5
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
				{
					i++;
					j++;
				}
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				j++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
				j++;
			}
		}
	}
	else if (encode == 3) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
				temp_w = W_Size + dis_x;
			else if (unicode == 0x000A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
				{
					i += 2;
					j++;
				}
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
				j++;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
				j++;
			}
		}
	}
	else if (encode == 6) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				temp_w = unicode_w + dis_x;
			}
			else if (unicode == 0x000A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
				{
					i += 2;
					j++;
				}
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i += 2;
				j++;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += temp_w;
				i += 2;
				j++;
			}
		}
	}
	if (row_num * H_Size > box_h)
		row_num = box_h / H_Size;
	// printf("row_num  %d   Ys  %d \r\n",row_num,Ys);     //debug
	if (row_num == 0)
		return 0;

	if (text_mode == 1)
	{
		c = (uint8_t *)Display_buff_temp;
		for (i = 0; i < j; i++)
		{
			c[i] = 0x2a;
		}
		
		data_w = (Ascii_w['*' - 0x20] + dis_x + 2)*j; // Record width

		len_max = j;
	}

	i = 0;
	disp_w = 0;

	if (Alignment == 0) // Align Left Center
	{
		X_start = Xs;
		Y_start = Ys + (box_h - row_num * H_Size) / 2;
	}
	else if (Alignment == 3) // Align Left Up
	{
		X_start = Xs;
		Y_start = Ys;
	}
	else if (Alignment == 6) // Align left lower
	{
		X_start = Xs;
		Y_start = Ye - row_num * H_Size;
	}
	else if (Alignment == 1) // Center Align Center
	{
		X_start = 0;
		Y_start = Ys + (box_h - row_num * H_Size) / 2;
	}
	else if (Alignment == 4) // Center Align Up
	{
		X_start = 0;
		Y_start = Ys;
	}
	else if (Alignment == 7) // Center Align lower
	{
		X_start = 0;
		Y_start = Ye - row_num * H_Size;
	}
	else if (Alignment == 2) // Align right Center
	{
		X_start = 0;
		Y_start = Ys + (box_h - row_num * H_Size) / 2;
	}
	else if (Alignment == 5) // Align right Up
	{
		X_start = 0;
		Y_start = Ys;
	}
	else if (Alignment == 8) // Align right lower
	{
		X_start = 0;
		Y_start = Ye - row_num * H_Size;
	}

	if (Y_start != Ys)
	{
		if (!enbackcolor)
		{
			if (mix)
				LT268_dispaly_CutPicture(Xs, Ys, Xs - mixpic.x, Ys - mixpic.y, box_w, Y_start - Ys, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
			else
				LT268_dispaly_CutPicture(Xs, Ys, Xs, Ys, box_w, Y_start - Ys, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
		}
		else
			LT268_TFT_FillColor(Xs, Ys, box_w, Y_start - Ys, BackColor);
	}

	// display
	if (encode == 4) // ASCII
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = (Ascii_w[c[i] - 0x20] + dis_x + 2);
			else if (c[i] == 0x0A)
				temp_w = 0; // newline

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if (mix)
							{
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);				
							}
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if (mix)
							{
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);						
							}
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, box_w, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);//LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						if(font_flag)
						{
							if (c[disp_i] == 0x31)
							{
								LT268_GrayScaleFont_dislay(4, FlashAddr, W_Size, H_Size, gray,
														   FontColor, BackColor, enbackcolor, mix, mixpic,
														   X_start, Y_start, Ascii_w[c[disp_i] - 0x20] + dis_x + 2 - 3, &c[disp_i]);
								X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2 - 3);
							}
							else
							{
								LT268_GrayScaleFont_dislay(4, FlashAddr, W_Size, H_Size, gray,
														   FontColor, BackColor, enbackcolor, mix, mixpic,
														   X_start, Y_start, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i]);
								X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
							}
						}
						else
						{
							LT268_GrayScaleFont_dislay(4, FlashAddr, W_Size, H_Size, gray,
													   FontColor, BackColor, enbackcolor, mix, mixpic,
													   X_start, Y_start, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i]);
							X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						}

						disp_i++;
					}
					else
						disp_i++;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
		}
	}
	else if (encode == 0) // GB2312
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0;

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{

					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i]);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);	
//printf("X_start=%d \r\n",X_start);						
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i] != 0xFF)
					{
						LT268_GrayScaleFont_dislay(0, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, W_Size + dis_x, &c[disp_i]);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}
				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{ // LT268_dispaly_CutPicture(Xs,Y_start, Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 1) // GBK
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0; // newline

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i]);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0x81 && c[disp_i + 1] >= 0x40 && c[disp_i] != 0xFF)
					{
						LT268_GrayScaleFont_dislay(1, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, W_Size + dis_x, &c[disp_i]);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{ // LT268_dispaly_CutPicture(Xs,Y_start, Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 2) // BIG5
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0; // newline

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i]);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i + 1] >= 0x40)
					{
						LT268_GrayScaleFont_dislay(2, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, W_Size + dis_x, &c[disp_i]);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{ // LT268_dispaly_CutPicture(Xs,Y_start, Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 3) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
				temp_w = W_Size + dis_x;
			else if (unicode == 0x000A)
				temp_w = 0; // newline

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1]);

						X_start += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{
						LT268_GrayScaleFont_dislay(3, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code));

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{ // LT268_dispaly_CutPicture(Xs,Y_start, Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 6) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				temp_w = unicode_w + dis_x;
			}
			else if (unicode == 0x000A)
				temp_w = 0; // newline

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1]);

						X_start += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{
						LT268_GrayScaleFont_dislay(3, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code));

						LT_ReadFlash(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode_temp - start_code) * (font_byte + 1), 1);
						X_start += (unicode_w + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{ // LT268_dispaly_CutPicture(Xs,Y_start, Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
							if (mix)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
							else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += temp_w;
				i += 2;
			}
		}
	}
	// printf("remaining part: Y_start %d , Xe %d  \r\n",Y_start,Ye);
	if (Y_start < Ye)
	{
		if (!enbackcolor)
		{
			if (mix)
				LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, box_w, Ye - Y_start + 1, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
			else
				LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, box_w, Ye - Y_start + 1, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, 0);
		}
		else
			LT268_TFT_FillColor(Xs, Y_start, box_w, Ye - Y_start + 1, BackColor);
	}
}



/*******************************************************************************
 * Function Name : LT_Print_zk_Font_BUFF
 * Description   : Buffer a string.
 * Input         :
 * Output        : None
 * Return        : None
 ********************************************************************/
uint16_t LT_Print_zk_Font_BUFF(
	uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size // font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	//,uint16_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	//,_PICINFO mixpic // mix picture info
	,
	uint16_t buf_w // width of buffer
	,
	uint16_t buf_h // height of buffer
	,
	uint8_t *buf // address of buffer
	,
	uint16_t buf_x // start x of buffer
	,
	uint16_t buf_y // start y of buffer
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
)
{
	uint16_t temp = 0, temp_H = 0, temp_L = 0;
	uint32_t i = 0;
	uint8_t gray, gray_bit;
	uint16_t disp_w = 0, disp_i = 0;
	uint16_t temp_w, box_w = 0;
	uint8_t unicode_w;
	uint16_t font_byte; // bytes of a single font
	uint8_t font_flag=1;	//当不是密码键盘时为1
	
	LT_ReadFlash(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash(&gray, FlashAddr + 8, 1);
	
	if(W_Size==30&&H_Size==40)	font_flag=0;
	if(font_flag)	Ascii_w[17]=10;	

	if (gray == 0)
		gray_bit = 1;
	else if (gray == 1)
		gray_bit = 2;
	else if (gray == 2)
		gray_bit = 4;
	font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;

	i = 0;
	if (encode == 4) // ASCII
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				box_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else
				break;
		}
	}
	else if (encode == 0) // GB2312
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				box_w += Ascii_w[c[i] - 0x20] + dis_x + 2;
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				box_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 1) // GBK
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				box_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				box_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 2) // BIG5
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				box_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				box_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 3) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1)
		{
			unicode = (c[i] << 8) + c[i + 1];
			if (unicode < 128 && unicode > 0x00)
			{
				box_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				box_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 6) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1)
		{
			unicode = (c[i] << 8) + c[i + 1];
			if (unicode < 128 && unicode > 0x00)
			{
				box_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				box_w += (unicode_w + dis_x);
				i += 2;
			}
			else
				break;
		}
	}

	if (Alignment == 0)
		buf_x = buf_x;
	else if (Alignment == 1)
		buf_x = buf_x - box_w / 2;
	else if (Alignment == 2)
		buf_x = buf_x - box_w + 1;


	i = 0;
	if (encode == 4) // ASCII
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = (Ascii_w[c[i] - 0x20] + dis_x + 2);
			// else if(c[i]==0x0A)                temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i; disp_i++)
				{
					if (font_flag)
					{
						if (c[disp_i] == 0x31)
						{
							LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
															FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2 - 3, &c[disp_i],
															buf_x, buf_y, buf_w, buf);
							buf_x += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2 - 3);
						}
						else
						{
							LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
															FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
															buf_x, buf_y, buf_w, buf);
							buf_x += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						}
					}
					else
					{
						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
					}					
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
		}
	}
	else if (encode == 0) // GB2312
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			// else if(c[i]==0x0A)                temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i] != 0xFF)
					{
						LT268_GrayScaleFont_dislay_BUFF(0, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 1) // GBK
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			//		  else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0x81 && c[disp_i + 1] >= 0x40 && c[disp_i] != 0xFF)
					{

						LT268_GrayScaleFont_dislay_BUFF(1, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 2) // BIG5
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
				temp_w = W_Size + dis_x;
			//		  else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i + 1] >= 0x40)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 3) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
				temp_w = W_Size + dis_x;
			//		  else if(c[i]==0x0A)                                   temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code),
														buf_x, buf_y, buf_w, buf);

						buf_x += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 6) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				temp_w = (unicode_w + dis_x);
			}
			//		  else if(c[i]==0x0A)                                   temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code),
														buf_x, buf_y, buf_w, buf);

						LT_ReadFlash(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode_temp - start_code) * (font_byte + 1), 1);
						buf_x += (unicode_w + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += temp_w;
				i += 2;
			}
		}
	}

	return 0;
}

/***********************************************************************************
* Function Name : text_display
* Description   : Show text.
* Input         : - type: text info sources
				  - buff: text info
* Output        : None
* Return        : None
************************************************************************************/
void text_display(uint8_t type, uint8_t *buff)
{
	uint16_t xs, ys, xe, ye; // Display box
	uint8_t Zk_id, w, h;	 // Font ID
	uint8_t encode;			 // encoding type
	uint8_t Alignment, transparent, star;
	uint32_t fcolor, bcolor; // The foreground color of the font, The background color of the font
	uint16_t p_add, p_len, pointer;
	uint32_t zk_addr;
	uint8_t buff1[4] = {0};
	uint32_t value=0;
	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8)) * 2;
		p_len = buff[7] + (buff[8] << 8);
		xs = buff[9] + (buff[10] << 8);
		ys = buff[11] + (buff[12] << 8);
		xe = buff[13] + (buff[14] << 8);
		ye = buff[15] + (buff[16] << 8);
		w = buff[17];
		h = buff[18];
		Zk_id = buff[19];
		encode = buff[20];
		Alignment = buff[21];
		bcolor = buff[22] + (buff[23] << 8) + (buff[24] << 16);
		fcolor = buff[25] + (buff[26] << 8) + (buff[27] << 16);
		transparent = buff[28] & 0x01;
		star = (buff[28] & 0x02) >> 1;
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8)) * 2;
		p_len = var[pointer + 3] + (var[pointer + 4] << 8);
		xs = var[pointer + 5] + (var[pointer + 6] << 8);
		ys = var[pointer + 7] + (var[pointer + 8] << 8);
		xe = var[pointer + 9] + (var[pointer + 10] << 8);
		ye = var[pointer + 11] + (var[pointer + 12] << 8);
		w = var[pointer + 13];
		h = var[pointer + 14];
		Zk_id = var[pointer + 15];
		encode = var[pointer + 16];
		Alignment = var[pointer + 17];
		bcolor = var[pointer + 18] + (var[pointer + 19] << 8) + (var[pointer + 20] << 16);
		fcolor = var[pointer + 21] + (var[pointer + 22] << 8) + (var[pointer + 23] << 16);
		transparent = var[pointer + 24] & 0x01 ;
		star = (var[pointer + 24] & 0x02) >> 1;	
	}
	
	if (Pop_up_flag == 1) // Popup offset
	{
		xs += Pop_up_x;
		ys += Pop_up_y;
		xe += Pop_up_x;
		ye += Pop_up_y;
	}

	//LT_ReadFlash(buff1, addr_index[2] + Zk_id * 8, 4);
	//zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);

	/*if(p_add==0x1000*2)		
	{
		Mode_Flag=0;
		if(pic_id==3) //计数器
		{	
			var[p_add]=Mode1_count_ALL/10000+'0';var[p_add+1]=Mode1_count_ALL/1000%10+'0';var[p_add+2]=Mode1_count_ALL/100%10+'0';var[p_add+3]=Mode1_count_ALL/10%10+'0';var[p_add+4]=Mode1_count_ALL%10+'0';		
		}			
		else
		{
			value = ((uint32_t)IO_READ8(OneCupH_sAddr)<<8) + IO_READ8(OneCupL_sAddr);//第一杯记录
			if(value>30000)
			{
				value = 0;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[1] = value>>8;
				W_buff[2] = value & 0XFF;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
			}
			var[p_add]=value/10000+'0';var[p_add+1]=value/1000%10+'0';var[p_add+2]=value/100%10+'0';var[p_add+3]=value/10%10+'0';var[p_add+4]=value%10+'0';
		}	
	}
	else if(p_add==0x1010*2)
	{
		Mode_Flag=1;
		if(pic_id==3)
		{	
			var[p_add]=Mode2_count_ALL/10000+'0';var[p_add+1]=Mode2_count_ALL/1000%10+'0';var[p_add+2]=Mode2_count_ALL/100%10+'0';var[p_add+3]=Mode2_count_ALL/10%10+'0';var[p_add+4]=Mode2_count_ALL%10+'0';			
		}			
		else	
		{
			value = ((uint32_t)IO_READ8(TwoCupH_sAddr)<<8) + IO_READ8(TwoCupL_sAddr);//第二杯记录
			if(value>30000)
			{
				value = 0;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[3] = value>>8;
				W_buff[4] = value & 0XFF;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
			}
			var[p_add]=value/10000+'0';var[p_add+1]=value/1000%10+'0';var[p_add+2]=value/100%10+'0';var[p_add+3]=value/10%10+'0';var[p_add+4]=value%10+'0';	
		}
	}
	else if(p_add==0x1020*2)
	{
		Mode_Flag=2;
		if(pic_id==3)
		{	
			var[p_add]=Mode3_count_ALL/10000+'0';var[p_add+1]=Mode3_count_ALL/1000%10+'0';var[p_add+2]=Mode3_count_ALL/100%10+'0';var[p_add+3]=Mode3_count_ALL/10%10+'0';var[p_add+4]=Mode3_count_ALL%10+'0';		
		}			
		else	
		{
			value = ((uint32_t)IO_READ8(ThreeCupH_sAddr)<<8) + IO_READ8(ThreeCupL_sAddr);//第三杯记录
			if(value>30000)
			{
				value = 0;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[5] = value>>8;
				W_buff[6] = value & 0XFF;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
			}
			var[p_add]=value/10000+'0';var[p_add+1]=value/1000%10+'0';var[p_add+2]=value/100%10+'0';var[p_add+3]=value/10%10+'0';var[p_add+4]=value%10+'0';	
		}
	}
	else if(p_add==0x1030*2)
	{
		Mode_Flag=3;
		if(pic_id==3)
		{	
			var[p_add]=(Count_value_ALL/1000)/10000+'0';var[p_add+1]=(Count_value_ALL/1000)/1000%10+'0';var[p_add+2]=(Count_value_ALL/1000)/100%10+'0';var[p_add+3]=(Count_value_ALL/1000)/10%10+'0';var[p_add+4]=(Count_value_ALL/1000)%10+'0';			
		}			
		else	
		{
			value = ((uint32_t)IO_READ8(AutoCupH_sAddr)<<8) + IO_READ8(AutoCupL_sAddr);//第四杯记录
			//printf("333333333333333333333AutoCupH_sAddr = %d \r\n",value);
			if(value>30000)
			{
				value = 0;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[7] = value>>8;
				W_buff[8] = value & 0XFF;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
			}
			var[p_add]=value/10000+'0';var[p_add+1]=value/1000%10+'0';var[p_add+2]=value/100%10+'0';var[p_add+3]=value/10%10+'0';var[p_add+4]=value%10+'0';
		}
//		var[p_add]=Count_value/10000+'0';var[p_add+1]=Count_value/1000%10+'0';var[p_add+2]=Count_value/100%10+'0';var[p_add+3]=Count_value/10%10+'0';var[p_add+4]=Count_value%10+'0';			
	}*/

	LT_ReadFlash(buff1, addr_index[2] + Zk_id * 8, 4);
	zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);


	if (!page_buff_flag)
	{
		LT_Print_zk_Font(encode, zk_addr,
						 LAY_BUFF1, LCD_XSIZE_TFT, w, h, Alignment, fcolor, bcolor, transparent, 0, PICINFO[0], star,
						 xs, ys, xe, ye,
						 0, 0, &var[p_add], p_len * 2);
	}
	else
	{
		LT_Print_zk_Font_BUFF(encode, zk_addr,
			LAY_BUFF1, LCD_XSIZE_TFT, w, h, Alignment, fcolor, bcolor, transparent,
			LCD_XSIZE_TFT, LCD_YSIZE_TFT, m_PngData, xs, ys,
			0, 0, &var[p_add], p_len * 2);
	}
}

/***********************************************************************************
* Function Name : data_display
* Description   : Show numbers in font.
* Input         : - type: data info sources
				  - buff: data info
* Output        : None
* Return        : None
************************************************************************************/
void data_display(uint8_t type, uint8_t *buff)
{
	uint16_t x, y;
	uint8_t font_w, font_h;
	uint32_t fcolor; // The foreground color of the font
	uint16_t p_add, pointer;
	uint8_t zk_id, Alignment;
	uint8_t N_int, D_int;
	uint8_t unit_len;
	uint8_t data_type;
	uint8_t i, Symbol = 0, n = 0, k = 0;
	uint64_t value_8 = 0, ll;
	uint32_t value_4 = 0;
	uint16_t value_2 = 0;
	uint8_t value_1 = 0;
	uint16_t dx, dy, dw, dh;
	uint32_t zk_addr;
	uint8_t buff1[4] = {0};

	memset(Display_buff, 0, 100);

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8)) * 2;
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		fcolor = buff[11] + (buff[12] << 8) + (buff[13] << 16);
		zk_id = buff[14];
		font_w = buff[15];
		Alignment = buff[16];
		N_int = buff[17];
		D_int = buff[18];
		data_type = buff[19];
		unit_len = buff[20];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer] + (var[pointer + 1] << 8)) * 2;
		x = var[pointer + 2] + (var[pointer + 3] << 8);
		y = var[pointer + 4] + (var[pointer + 5] << 8);
		fcolor = var[pointer + 6] + (var[pointer + 7] << 8) + (var[pointer + 8] << 16);
		zk_id = var[pointer + 9];
		font_w = var[pointer + 10];
		Alignment = var[pointer + 11];
		N_int = var[pointer + 12];
		D_int = var[pointer + 13];
		data_type = var[pointer + 14];
		unit_len = var[pointer + 15];
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}

	if (data_type == 0x00)
	{
		value_8 = var[p_add + 1];
	}
	else if (data_type == 0x01)
	{
		value_8 = (var[p_add] << 8) + var[p_add + 1];
	}
	else if (data_type == 0x02)
	{
		value_8 = (0xFF000000 & (var[p_add] << 24)) | (var[p_add + 1] << 16) | (var[p_add + 2] << 8) | var[p_add + 3];
	}
	else if (data_type == 0x03)
	{
		value_8 = (0xFF000000 & (var[p_add] << 24)) + (var[p_add + 1] << 16) + (var[p_add + 2] << 8) + var[p_add + 3];
		value_8 = ((value_8 << 24) << 8) + (0xFF000000 & (var[p_add + 4] << 24)) + (var[p_add + 5] << 16) + (var[p_add + 6] << 8) + var[p_add + 7];
		if (value_8 >= 0x8000000000000000)
		{
			value_8 = ~value_8 + 1;
			Symbol = 1;
		}
	}
	else if (data_type == 0x80)
	{
		value_1 = var[p_add + 1];
		if (value_1 >= 0x80)
		{
			value_1 = ~value_1 + 1;
			Symbol = 1;
		}
		value_8 = value_1;
	}
	else if (data_type == 0x81)
	{
		value_2 = (var[p_add] << 8) + var[p_add + 1];
		if (value_2 >= 0x8000)
		{
			value_2 = ~value_2 + 1;
			Symbol = 1;
		}
		value_8 = value_2;
	}
	else if (data_type == 0x82)
	{
		value_4 = (var[p_add] << 24) + (var[p_add + 1] << 16) + (var[p_add + 2] << 8) + var[p_add + 3];
		if (value_4 >= 0x80000000)
		{
			value_4 = ~value_4 + 1;
			Symbol = 1;
		}
		value_8 = value_4;
	}
	else if (data_type == 0x83)
	{
		value_8 = (0xFF000000 & (var[p_add] << 24)) + (var[p_add + 1] << 16) + (var[p_add + 2] << 8) + var[p_add + 3];
		value_8 = ((value_8 << 24) << 8) + (0xFF000000 & (var[p_add + 4] << 24)) + (var[p_add + 5] << 16) + (var[p_add + 6] << 8) + var[p_add + 7];
		if (value_8 >= 0x8000000000000000)
		{
			value_8 = ~value_8 + 1;
			Symbol = 1;
		}
	}

	ll = pow(10, N_int + D_int);
	value_8 = value_8 % ll;
	if (Symbol == 1)
		Display_buff[0] = '-';

	ll = value_8;

	do
	{ // Get the number of digits
		n++;
		ll /= 10;
	} while (ll > 0);
	if (D_int > 0) // With decimal point
	{
		if (D_int >= n)
		{
			Display_buff[Symbol] = '0';
			Display_buff[Symbol + 1] = '.';
			for (i = n; D_int > i; i++)
			{
				Display_buff[Symbol + 2 + i - n] = '0';
			}

			sprintf(&Display_buff[Symbol + 2 + D_int - n], "%lld", value_8);

			for (k = 0; k < unit_len; k++)
			{
				if (type == 0)
				{
					Display_buff[2 + D_int + k] = buff[21 + k];
				}
				else if (type == 1)
				{
					Display_buff[2 + D_int + k] = var[pointer + 16 + i];
				}
			}
		}
		else
		{
			sprintf(&Display_buff[Symbol], "%lld", value_8);

			for (i = 0; i < D_int; i++)
			{
				Display_buff[n + Symbol - i] = Display_buff[n - 1 + Symbol - i];
			}

			Display_buff[n + Symbol - D_int] = '.';

			for (k = 0; k < unit_len; k++)
			{
				if (type == 0)
				{
					Display_buff[Symbol + n + 1 + k] = buff[21 + k];
				}
				else if (type == 1)
				{
					Display_buff[Symbol + n + 1 + k] = var[pointer + 16 + i];
				}
			}
		}
	}
	else
	{
		sprintf(&Display_buff[Symbol], "%lld", value_8);

		for (k = 0; k < unit_len; k++)
		{
			if (type == 0)
			{
				Display_buff[Symbol + n + k] = buff[21 + k];
			}
			else if (type == 1)
			{
				Display_buff[Symbol + n + k] = var[pointer + 16 + i];
			}
		}
		Display_buff[Symbol + n + k] = 0xFF;
	}

	if (Alignment == 0) // left
	{

		if (D_int > 0)
		{
			if ((data_type & 0x80) > 0)
				dw = font_w * (N_int + D_int + 2);
			else
				dw = font_w * (N_int + D_int + 1);
		}
		else
		{
			if ((data_type & 0x80) > 0)
				dw = font_w * (N_int + 1);
			else
				dw = font_w * N_int;
		}
		dw = dw / 2;
		dx = x;
		dy = y;
	}
	else if (Alignment == 2) // right
	{
		if (D_int > 0)
		{
			if ((data_type & 0x80) > 0)
				dw = font_w * (N_int + D_int + 2);
			else
				dw = font_w * (N_int + D_int + 1);
		}
		else
		{
			if ((data_type & 0x80) > 0)
				dw = font_w * (N_int + 1);
			else
				dw = font_w * N_int;
		}
		dw = dw / 2;
		dx = x - dw;
		dy = y;
	}
	else if (Alignment == 1) // center
	{
		if (D_int > 0)
		{
			if ((data_type & 0x80) > 0)
				dw = font_w * (N_int + D_int + 2);
			else
				dw = font_w * (N_int + D_int + 1);
		}
		else
		{
			if ((data_type & 0x80) > 0)
				dw = font_w * (N_int + 1);
			else
				dw = font_w * N_int;
		}
		dw = dw / 2;
		dx = x - dw / 2;
		dy = y;
	}

	LT_ReadFlash(buff1, addr_index[2] + zk_id * 8, 4);
	zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
	LT_ReadFlash(&font_h, zk_addr + 3, 1);
	dh = font_h;

	// debug
	// printf("dx    %d   %d   %d   %d      \r\n  ",dx,dy,dx+dw,dy+dh);

	LT_Print_zk_Font(4, zk_addr,
					 LAY_BUFF1, LCD_XSIZE_TFT, font_w, font_h, Alignment, fcolor, Black, 0, 0, PICINFO[0], 0,
					 dx, dy, dx + dw, dy + dh,
					 0, 0, Display_buff, sizeof(Display_buff));
}

LT_ENCODER_ LT_encoder = {0};

/***********************************************************************************
* Function Name : pic_date_display
* Description   : Display data in picture mode.
* Input         : - type: data info sources
				  - buff: data info
* Output        : None
* Return        : None
************************************************************************************/
void pic_date_display(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, p_len, pointer;
	uint16_t x, y, xd, w, x1;
	uint16_t simage, eimage;
	uint8_t data_type, I_num, D_num, Alig, i = 0, num = 0;
	uint8_t flag = 0, nflag = 0;
	uint16_t num_w, dot_w, neg_w, h, canvas_numw, canvas_dotw, canvas_negw;
	uint32_t value3 = 0;
	int32_t value2 = 0;
	int8_t value0 = 0;
	int16_t value1 = 0;
	int64_t value = 0;
	uint16_t tft_x, buf_x;
	uint8_t buff1[12] = {0};
	uint8_t leading_zero = 0;//

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8)) * 2;
		data_type = buff[7];
		x = buff[8] + (buff[9] << 8);
		y = buff[10] + (buff[11] << 8);
		I_num = buff[12];
		D_num = buff[13];
		Alig = buff[14] & 0x7F;
		leading_zero = (buff[14] & 0x80) >> 7;
		simage = buff[15] + (buff[16] << 8);
		eimage = buff[17] + (buff[18] << 8);
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8));
		data_type = var[pointer + 3];
		x = var[pointer + 4] + (var[pointer + 5] << 8);
		y = var[pointer + 6] + (var[pointer + 7] << 8);
		I_num = var[pointer + 8];
		D_num = var[pointer + 9];
		Alig = var[pointer + 10] & 0x7F;
		leading_zero = (var[pointer + 10] & 0x80) >> 7;
		simage = var[pointer + 11] + (var[pointer + 12] << 8);
		eimage = var[pointer + 13] + (var[pointer + 14] << 8);
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}
	if (data_type == 0x00)
	{
		value3 = var[p_add + 1];
		value = value3;
	}
	else if (data_type == 0x01)
	{
		value3 = (var[p_add] << 8) + var[p_add + 1];
		value = value3;
	}
	else if (data_type == 0x02)
	{
		value3 = (0xFF000000 & (var[p_add] << 24)) | (var[p_add + 1] << 16) | (var[p_add + 2] << 8) | var[p_add + 3];
		value = value3;
	}
	else if (data_type == 0x80)
	{
		value0 = var[p_add + 1];
		value = value0;
	}
	else if (data_type == 0x81)
	{
		if(p_add==0x1926*2)	
		{
			value1 = Mode1_count_ALL*1 + Mode2_count_ALL*2 + Mode3_count_ALL*3;				
			//printf("555555555555555555555Mode1_count_ALL = %d \r\n",Mode1_count_ALL);
		}
		else if(p_add==0x1925*2)	
		{
			//printf("66666666666666666666666Mode1_count_ALL = %d \r\n",Mode1_count_ALL);
			value1 = (((uint32_t)IO_READ8(OneCupH_sAddr)<<8) + IO_READ8(OneCupL_sAddr))*1 + (((uint32_t)IO_READ8(TwoCupH_sAddr)<<8) + IO_READ8(TwoCupL_sAddr))*2 + (((uint32_t)IO_READ8(ThreeCupH_sAddr)<<8) + IO_READ8(ThreeCupL_sAddr))*3;		
		}
		else if(p_add==0x1AA1*2)	
		{
			//printf("77777777777777777777Mode1_count_ALL = %d \r\n",Mode1_count_ALL);
			value1 = Mode1_count_ALL;
		}
		else if(p_add==0x1AA2*2)	
		{
			value1 = Mode2_count_ALL;
		}
		else if(p_add==0x1AA3*2)	
		{
			value1 = Mode3_count_ALL;
		}
		else if(p_add==0x1AA4*2)	
		{
			value1 = (((uint32_t)IO_READ8(Cup_sAddr+12)<<8) + IO_READ8(Cup_sAddr+13));
		}
		//else if(p_add==0x1931*2)	
		//{
		//	value1 = ((uint32_t)IO_READ8(OneCupH_sAddr)<<8) + IO_READ8(OneCupL_sAddr)*1;
		//}
		else value1 = (var[p_add] << 8) + var[p_add + 1];
		value = value1;
	}
	else if (data_type == 0x82)
	{
		value2 = (var[p_add] << 24) | (var[p_add + 1] << 16) | (var[p_add + 2] << 8) | var[p_add + 3];
		value = value2;
	}
	else if (data_type == 0x83)
	{
		value = (0xFF000000 & (var[p_add] << 24)) + (var[p_add + 1] << 16) + (var[p_add + 2] << 8) + var[p_add + 3];
		value = ((value << 24) << 8) + (0xFF000000 & (var[p_add + 4] << 24)) + (var[p_add + 5] << 16) + (var[p_add + 6] << 8) + var[p_add + 7];
	}

	memset(Display_buff, 0, 50);

	if (value < 0)
	{
		Display_buff[num] = 11; // minus
		value = value * (-1);	// Become an integer
		nflag = 1;
		num++;
	}

	if (value < 1000000000000000000)
		value = value % ((int64_t)pow(10, I_num + D_num));

	for (i = 0; i < I_num; i++) // Integer part
	{
		Display_buff[num] = value / (int64_t)pow(10, I_num - i - 1 + D_num);
		//if (Display_buff[num] != 0 || flag == 1)
		if (leading_zero == 0)
		{
		if (Display_buff[num] != 0 || flag == 1)
		{
			num++;
			flag = 1; // The first digit is not 0
		}
		}
		else
		{
			num++;
			flag = 1; // The first digit is not 0
		}

		value = value % (int64_t)pow(10, I_num - i - 1 + D_num);
	}

	if (flag == 0)
	{
		Display_buff[num] = 0;
		num++;
	}

	if (D_num > 0)
	{
		Display_buff[num] = 10; //"."
		num++;
	}

	for (i = 0; i < D_num; i++) // digit after point
	{
		Display_buff[num] = value / (int64_t)pow(10, D_num - i - 1);
		num++;
		value = value % (int64_t)pow(10, D_num - i - 1);
	}

	LT_ReadFlash(buff1, addr_index[10] + 12 * simage, 12);
	pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
	num_w = buff1[4] + (buff1[5] << 8);
	h = buff1[6] + (buff1[7] << 8);
	pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
	pic_flag = buff1[11];

	PICINFO[0].w = num_w;
	PICINFO[0].h = h;
	PICINFO[0].len = pic_len;
	PICINFO[0].flag = pic_flag;
	PICINFO[0].addr = pic_add;

	if (D_num > 0) // have point
	{
		LT_ReadFlash(buff1, addr_index[10] + 12 * (simage + 10), 12); 
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		dot_w = buff1[4] + (buff1[5] << 8);

		PICINFO[1].w = dot_w;
		PICINFO[1].addr = pic_add;
	}

	if (nflag == 1) // have minus
	{
		LT_ReadFlash(buff1, addr_index[10] + 12 * (simage + 11), 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		neg_w = buff1[4] + (buff1[5] << 8);

		PICINFO[2].w = neg_w;
		PICINFO[2].addr = pic_add;
	}

	xd = 0;
	w = 0;
	i = 0;
	for (i = 0; i < num; i++) // display part
	{
		if (Display_buff[i] >= 0 && Display_buff[i] <= 9)
		{
			LT_ReadFlash(buff1, addr_index[10] + 12 * (simage + Display_buff[i]), 5);
			num_w = buff1[4] + (buff1[5] << 8);
			xd += num_w;
		}
		else if (Display_buff[i] == 10)
			xd += dot_w;
		else if (Display_buff[i] == 11)
			xd += neg_w;
	}

	if (pdata_D_w[pdata_D_num] > xd) // The previous data is wider than the current data, and more content needs to be cleared
	{
		w = pdata_D_w[pdata_D_num];
		if (Alig == 0) // left
		{
			tft_x = x;
			buf_x = 0;
		}
		else if (Alig == 1) // center
		{
			tft_x = x - w / 2;
			buf_x = (w - xd) / 2;
		}
		else if (Alig == 2) // right
		{
			tft_x = x - w + 1;
			buf_x = w - xd;
		}
	}
	else
	{
		w = xd;
		buf_x = 0;
		if (Alig == 0)
			tft_x = x;
		else if (Alig == 1)
			tft_x = x - w / 2;
		else if (Alig == 2)
			tft_x = x - w + 1;
	}

if(!page_buff_flag)//JOFI
{
	LT268_pic_to_buffer(0, 0, w, m_PngData,
						tft_x, y, LCD_XSIZE_TFT, FullScreen_addr,
						w, h, 0);

	i = 0;
	for (i = 0; i < num; i++) // display
	{
		if (Display_buff[i] >= 0 && Display_buff[i] <= 9)
		{
			LT_ReadFlash(buff1, addr_index[10] + 12 * (simage + Display_buff[i]), 5);
			pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			num_w = buff1[4] + (buff1[5] << 8);

			LT268_pic_to_buffer(buf_x, 0, w, m_PngData,
								0, 0, num_w, pic_add,
								num_w, h, pic_flag);
			buf_x += num_w;
		}
		else if (Display_buff[i] == 10)
		{
			LT268_pic_to_buffer(buf_x, 0, w, m_PngData,
								0, 0, PICINFO[1].w, PICINFO[1].addr,
								PICINFO[1].w, h, pic_flag);
			buf_x += dot_w;
		}
		else if (Display_buff[i] == 11)
		{
			LT268_pic_to_buffer(buf_x, 0, w, m_PngData,
								0, 0, PICINFO[2].w, PICINFO[2].addr,
								PICINFO[2].w, h, pic_flag);
			buf_x += neg_w;
		}
	}
      LT268_buffer_to_TFT(0, 0, w, m_PngData,
 						tft_x, y, w, h);
}
else
{
		i = 0;
	for (i = 0; i < num; i++) // display
	{
		if (Display_buff[i] >= 0 && Display_buff[i] <= 9)
		{
			LT_ReadFlash(buff1, addr_index[10] + 12 * (simage + Display_buff[i]), 5);
			pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			num_w = buff1[4] + (buff1[5] << 8);

			LT268_pic_to_buffer(tft_x, y, LCD_XSIZE_TFT, m_PngData,
 								0, 0, num_w, pic_add,
								num_w, h, pic_flag);
			tft_x += num_w;
 		}
		else if (Display_buff[i] == 10)
		{
			   LT268_pic_to_buffer(tft_x, y, LCD_XSIZE_TFT, m_PngData,
  								0, 0, PICINFO[1].w, PICINFO[1].addr,
								PICINFO[1].w, h, pic_flag);
			tft_x += dot_w;
  		}
		else if (Display_buff[i] == 11)
		{
             LT268_pic_to_buffer(tft_x, y, LCD_XSIZE_TFT, m_PngData,
  								0, 0, PICINFO[2].w, PICINFO[2].addr,
								PICINFO[2].w, h, pic_flag);
			 tft_x += neg_w; 
		}
	}
}	

	pdata_D_w[pdata_D_num] = xd; // Record width
}

/***********************************************************************************
* Function Name : gif_display
* Description   : Show picture of gif.
* Input         : - type: gif info sources
				  - buff: gif info
* Output        : None
* Return        : None
************************************************************************************/
void gif_display(uint8_t type, uint8_t *buff)
{
	uint8_t rbuff[16], i;
	uint16_t p_add, p_len, pointer;
	uint16_t x, y, w, h;
	uint16_t V_stop, V_start, gif_id, V_once;
	uint8_t reset_En, mode, t_d;
	uint32_t pic_addr;

	if (type == 0) // instruction information source is configuration file
	{
		p_add = buff[5] + (buff[6] << 8);
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		w = buff[11] + (buff[12] << 8);
		h = buff[13] + (buff[14] << 8);
		gif_id = buff[15] + (buff[16] << 8);
		reset_En = buff[17];
		t_d = buff[18];
		V_start = buff[19] + (buff[20] << 8);
		V_stop = buff[21] + (buff[22] << 8);
		mode = buff[23];
		V_once = buff[24] + (buff[25] << 8);
		for (i = 0; i < 32; i += 4)
		{
			gGif_Info[Gif_num].var_addr[i / 4] = buff[26 + i] + (buff[26 + i + 1] << 8);
			gGif_Info[Gif_num].var[i / 4] = buff[26 + i + 2] + (buff[26 + i + 3] << 8);
		}
		for(i=0;i<8;i++)
			Var_AddrRemapping(&gGif_Info[Gif_num].var_addr[i]);
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = buff[2] + (buff[3] << 8);
		p_add = buff[pointer] + (buff[pointer + 1] << 8);
		x = buff[pointer + 2] + (buff[pointer + 3] << 8);
		y = buff[pointer + 4] + (buff[pointer + 5] << 8);
		w = buff[pointer + 6] + (buff[pointer + 7] << 8);
		h = buff[pointer + 8] + (buff[pointer + 9] << 8);
		gif_id = buff[pointer + 10] + (buff[pointer + 11] << 8);
		reset_En = buff[pointer + 12];
		t_d = buff[pointer + 13];
		V_start = buff[pointer + 14] + (buff[pointer + 15] << 8);
		V_stop = buff[pointer + 16] + (buff[pointer + 17] << 8);
		mode = buff[pointer + 18];
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}

	gGif_Info[Gif_num].p_add = p_add;
	gGif_Info[Gif_num].x = x;
	gGif_Info[Gif_num].y = y;
	gGif_Info[Gif_num].w = w;
	gGif_Info[Gif_num].h = h;
	gGif_Info[Gif_num].gif_id = gif_id;
	gGif_Info[Gif_num].reset_En = reset_En;
	gGif_Info[Gif_num].t_d = t_d;
	gGif_Info[Gif_num].V_stop = V_stop;
	gGif_Info[Gif_num].V_start = V_start;
	gGif_Info[Gif_num].V_once = V_once;
	gGif_Info[Gif_num].mode = mode;
	gGif_Info[Gif_num].p_c = 0;
	LT_ReadFlash(rbuff, addr_index[8] + gif_id * 8, 8);
	gGif_Info[Gif_num].addr = rbuff[0] + (rbuff[1] << 8) + (rbuff[2] << 16) + (rbuff[3] << 24);
	gGif_Info[Gif_num].total = rbuff[4] + (rbuff[5] << 8) + (rbuff[6] << 16);
	
	if(page_buff_flag)
{
		LT_ReadFlash(rbuff, gGif_Info[Gif_num].addr, 16);
		pic_addr = rbuff[0] + (rbuff[1] << 8) + (rbuff[2] << 16) + (rbuff[3] << 24);
		pic_flag = rbuff[15];
//		printf("pic_addr=0x%x pic_flag=0x%d \r\n",pic_addr,pic_flag);
		LT268_pic_to_buffer(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, 320, m_PngData,
							0, 0, gGif_Info[Gif_num].w, pic_addr,
							gGif_Info[Gif_num].w, gGif_Info[Gif_num].h, pic_flag);
	  Gif_num++;
	return;
}
	/*Display the first frame when stopping*/
	if (((var[gGif_Info[Gif_num].p_add * 2] << 8) + var[gGif_Info[Gif_num].p_add * 2 + 1]) == gGif_Info[Gif_num].V_stop)
	{
		LT_ReadFlash(rbuff, gGif_Info[Gif_num].addr, 16);
		pic_addr = rbuff[0] + (rbuff[1] << 8) + (rbuff[2] << 16) + (rbuff[3] << 24);
		pic_flag = rbuff[15];
//		printf("pic_addr=0x%x pic_flag=0x%d \r\n",pic_addr,pic_flag);
		if (pic_flag == 0)
			LT268_TFT_ShowPicture(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, gGif_Info[Gif_num].w, gGif_Info[Gif_num].h, pic_addr);
		else if (pic_flag == 1)
		{
			LT268_TFT_ShowPicture_Png(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, gGif_Info[Gif_num].w, gGif_Info[Gif_num].h, pic_addr);
		}		
		else if (pic_flag == 2)
		{
		LT268_pic_to_buffer(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, 320, m_PngData,
							0, 0, gGif_Info[Gif_num].w, Gif_addr,
							gGif_Info[Gif_num].w, gGif_Info[Gif_num].h, 2);	
		LT268_pic_to_buffer(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, 320, m_PngData,
							0, 0, gGif_Info[Gif_num].w, pic_addr,
							gGif_Info[Gif_num].w, gGif_Info[Gif_num].h, 2);	
		LT268_buffer_to_TFT(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, 320, m_PngData,
							gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, gGif_Info[Gif_num].w, gGif_Info[Gif_num].h);	
//			LT268_TFT_ShowPicture_Png_Pixel(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, gGif_Info[Gif_num].w, gGif_Info[Gif_num].h, pic_addr);printf("222 \r\n");
		}			
		else if (pic_flag == 2)
			LT268_TFT_ShowPicture_Png_Pixel(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, gGif_Info[Gif_num].w, gGif_Info[Gif_num].h, pic_addr);
		else if (pic_flag == 3 || pic_flag == 4 || pic_flag == 5)
			LT268_TFT_ShowPicture_zip(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, gGif_Info[Gif_num].w, gGif_Info[Gif_num].h, pic_addr);
	}

	LT_ShowGifPicture(Gif_num);
	Gif_num++;
}

uint8_t GIF_count_flag=0;
uint8_t LT_ShowGifPicture(uint8_t num)
{
	uint32_t pic_addr;
	uint8_t rbuff[16], i;
	
	if (((var[gGif_Info[num].p_add * 2] << 8) + var[gGif_Info[num].p_add * 2 + 1]) == gGif_Info[num].V_start)
	{
		gGif_Info[num].flag = 1;
		if (gGif_Info[num].p_c >= gGif_Info[num].total)
			gGif_Info[num].p_c = 0;

		LT_ReadFlash(rbuff, gGif_Info[num].addr + gGif_Info[num].p_c * 16, 16);

		pic_addr = rbuff[0] + (rbuff[1] << 8) + (rbuff[2] << 16) + (rbuff[3] << 24);
		pic_flag = rbuff[15];

		// In the keyboard input interface
		if (DioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gDio_Info[Dio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gDio_Info[Dio_num].Xs || gGif_Info[num].y > gDio_Info[Dio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gAio_Info[Aio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gAio_Info[Aio_num].Xs || gGif_Info[num].y > gAio_Info[Aio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gGBKio_Info[GBKio_num].Xs || gGif_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}
		
		LT268_pic_to_buffer(gGif_Info[num].x, gGif_Info[num].y, 320, m_PngData,
							0, 0, gGif_Info[num].w, Gif_addr,
							gGif_Info[num].w, gGif_Info[num].h, 2);	
		LT268_pic_to_buffer(gGif_Info[num].x, gGif_Info[num].y, 320, m_PngData,
							0, 0, gGif_Info[num].w, pic_addr,
							gGif_Info[num].w, gGif_Info[num].h, 2);								
	
		GIF_count_flag=1;
		Display_Count(0);
		GIF_count_flag=0;
		LT268_buffer_to_TFT(gGif_Info[num].x, gGif_Info[num].y, 320, m_PngData,
							gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h);		
		
		gGif_Info[num].p_c++;
	}
	else if (((var[gGif_Info[num].p_add * 2] << 8) + var[gGif_Info[num].p_add * 2 + 1]) == gGif_Info[num].V_once)
	{
		gGif_Info[num].flag = 1;
		if (gGif_Info[num].p_c >= gGif_Info[num].total)
		{
			var[gGif_Info[num].p_add * 2] = (gGif_Info[num].V_stop >> 8) & 0xFF;
			var[gGif_Info[num].p_add * 2 + 1] = (gGif_Info[num].V_stop) & 0xFF;
			for (i = 0; i < 8; i++)
			{
				if (gGif_Info[num].var_addr[i] != 0xFFFF && gGif_Info[num].var_addr[i] <= VAR_ADDR_E)
				{
					var[gGif_Info[num].var_addr[i] * 2] = (gGif_Info[num].var[i] >> 8) & 0xFF;
					var[gGif_Info[num].var_addr[i] * 2 + 1] = gGif_Info[num].var[i] & 0xFF;

					if (gGif_Info[num].var_addr[i] >= VAR_ADDR_S)
					{
						reg_operation(gGif_Info[num].var_addr[i]);
					}
				}
			}

			return 0;
		}

		LT_ReadFlash(rbuff, gGif_Info[num].addr + gGif_Info[num].p_c * 16, 16);
		pic_addr = rbuff[0] + (rbuff[1] << 8) + (rbuff[2] << 16) + (rbuff[3] << 24);
		pic_flag = rbuff[15];

		// In the keyboard input interface
		if (DioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gDio_Info[Dio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gDio_Info[Dio_num].Xs || gGif_Info[num].y > gDio_Info[Dio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gAio_Info[Aio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gAio_Info[Aio_num].Xs || gGif_Info[num].y > gAio_Info[Aio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gGBKio_Info[GBKio_num].Xs || gGif_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}

		if (pic_flag == 0)
			LT268_TFT_ShowPicture(gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h, pic_addr);
		else if (pic_flag == 1)
			LT268_TFT_ShowPicture_Png(gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h, pic_addr);
		else if (pic_flag == 2)
			LT268_TFT_ShowPicture_Png_Pixel(gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h, pic_addr);
		else if (pic_flag == 3 || pic_flag == 4 || pic_flag == 5)
			LT268_TFT_ShowPicture_zip(gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h, pic_addr);

		gGif_Info[num].p_c++;
	}
	else if (((var[gGif_Info[num].p_add * 2] << 8) + var[gGif_Info[num].p_add * 2 + 1]) == gGif_Info[num].V_stop)
	{
		// In the keyboard input interface
		if (DioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gDio_Info[Dio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gDio_Info[Dio_num].Xs || gGif_Info[num].y > gDio_Info[Dio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gAio_Info[Aio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gAio_Info[Aio_num].Xs || gGif_Info[num].y > gAio_Info[Aio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gGBKio_Info[GBKio_num].Xs || gGif_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}

		gGif_Info[num].flag = 1;
		if (gGif_Info[num].reset_En == 1) // gif reset
		{
			gGif_Info[num].p_c = 0;
		}
	}
	else if (((var[gGif_Info[num].p_add * 2] << 8) + var[gGif_Info[num].p_add * 2 + 1]) == 0xFFFF)
	{
		// In the keyboard input interface
		if (DioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gDio_Info[Dio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gDio_Info[Dio_num].Xs || gGif_Info[num].y > gDio_Info[Dio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gAio_Info[Aio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gAio_Info[Aio_num].Xs || gGif_Info[num].y > gAio_Info[Aio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gGBKio_Info[GBKio_num].Xs || gGif_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}
		if (gGif_Info[num].flag != 0)
		{

			LT268_dispaly_CutPicture(gGif_Info[num].x, gGif_Info[num].y,
									 gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);

			gGif_Info[num].flag = 0;
		}
		gGif_Info[num].p_c = 0;
	}
}

void show_gif(void)
{
	if (Gif_num > 0 && Gif_flag == 1)
	{
		Gif_flag = 0;

		for (uint8_t i = 0; i < Gif_num; i++)
			gGif_Info[i].t_c++;
		for (uint8_t i = 0; i < Gif_num; i++)
		{
			if (gGif_Info[i].t_c >= gGif_Info[i].t_d) // display picture of gif
			{
				LT_ShowGifPicture(i);
				gGif_Info[i].t_c = 0;
			}
		}
	}
}

/***********************************************************************************
* Function Name : qr_code
* Description   : Show QRcode.
* Input         : - type: QRcode info sources
				  - buff: QRcode info
* Output        : None
* Return        : None
************************************************************************************/
void qr_code(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, pointer, length;
	uint16_t i = 0, j = 0;
	uint16_t x1 = 0, y1 = 0, x, y;
	int32_t size = 49;
	uint8_t dxy = 0;
	uint8_t unit_pixle;
	uint16_t backgroud_size = 50; // White background magnification base

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8)) * 2;
		length = buff[7] + (buff[8] << 8);
		x = buff[9] + (buff[10] << 8);
		y = buff[11] + (buff[12] << 8);
		unit_pixle = buff[13];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (buff[pointer] + (buff[pointer + 1] << 8)) * 2;
		length = buff[pointer + 2] + (buff[pointer + 3] << 8);
		x = buff[pointer + 4] + (buff[pointer + 5] << 8);
		y = buff[pointer + 6] + (buff[pointer + 7] << 8);
		unit_pixle = buff[pointer + 8];
	}
	
	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}
	
#if QR_ENABLE
  EncodeData(&var[p_add]);

	// m_nSymbleSize: It's the real QR code size
	size = size * unit_pixle / m_nSymbleSize;						// Size of a single black pixel of the actual QR code
	dxy = (backgroud_size * unit_pixle - m_nSymbleSize * size) / 2; // The actual QR code is at the beginning of the white background
	y1 = y + dxy;

	LT268_TFT_FillColor(x, y, backgroud_size * unit_pixle, backgroud_size * unit_pixle, White); // Enlarged white background size

	// display
	for (i = 0; i < m_nSymbleSize; i++)
	{
		x1 = dxy + x;
		for (j = 0; j < m_nSymbleSize; j++)
		{
			if (m_byModuleData[i][j])
			{
				LT268_TFT_FillColor(x1, y1, size, size, Black);
			}
			x1 += size;
		}
		y1 += size;
	}
#endif
}

#define RTC_BLANK 20
uint8_t RTC_num = 0;
uint8_t RTC_flag = 0;
RTC_Info gRTC_Info[RTC_SIZE];
/***********************************************************************************
* Function Name : Display_RTC
* Description   : Show digital clock.
* Input         : - gRTC: digital clock info sources
				  - status: digital clock status
* Output        : None
* Return        : None
************************************************************************************/
uint8_t Display_RTC(RTC_Info *gRTC, uint8_t status)
{
	uint8_t buff[12] = {0};
	uint8_t flag = 0;
	uint16_t i = 0, ID[11];
	int8_t num = 0;
	uint16_t x_date = 0, x_time = 0, width = 0, high = 0;
	uint16_t id_start = gRTC->ID_start;
	uint16_t x = gRTC->x;
	uint16_t y = gRTC->y;
	uint8_t mode = gRTC->mode;
	uint16_t x_src, y_src, x_des, y_des, w_real, h_real, cnt;

//	if (mode == 0) // YY/MM/DD HH/MM/SS
	if (mode == 0 || mode == 8) // Year/month/day/hour/minute/second
	{
		/* Display date*/
		num = 0;
		if (calendar.w_year / 1000)
			num = 0; // The number of digits is different
		else
		{
			num--;
			if ((calendar.w_year / 100 % 10) == 0)
			{
				num--;
				if ((calendar.w_year / 10 % 10) == 0)
					num--;
			}
		}

		if (num >= 0)
			ID[num] = (calendar.w_year) / 1000;
		if (num + 1 >= 0)
			ID[num + 1] = (calendar.w_year) / 100 % 10;
		if (num + 2 >= 0)
			ID[num + 2] = (calendar.w_year) / 10 % 10;
		if (num + 3 >= 0)
			ID[num + 3] = (calendar.w_year) % 10;
		ID[num + 4] = 11;
		if (((calendar.w_month) / 10 % 10) == 0)
			num--;
		else
			ID[num + 5] = (calendar.w_month) / 10 % 10;
		ID[num + 6] = (calendar.w_month) % 10;
		ID[num + 7] = 12;

		if (((calendar.w_date) / 10 % 10) == 0)
			num--;
		else
			ID[num + 8] = (calendar.w_date) / 10 % 10;

		ID[num + 9] = (calendar.w_date) % 10;
		if (mode == 0)
			cnt = num + 9;
		else
		{
			ID[num + 10] = 13;
			cnt = num + 10;
		}
		
		for (i = 0; i <= cnt; i++)
		{
			if (id_start + ID[i] >= addr_index[11])
				continue; // ICON is available
			LT_ReadFlash(buff, addr_index[10] + 12 * (id_start + ID[i]), 12);
			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];

			// Record the height and flag of the first valid ICON, and the following ICON arrangement shall be subject to this
			if (i == 0)
			{
				high = pic_h;
				flag = pic_flag;
			}

			if (pic_len != 0 && pic_flag != 0xFF) // ICON is not empty
			{
				x_date += pic_w;
			}
		}
		
		/*In the keyboard input interface*/
		if (DioKb_flag == 1)
		{
			if (!(x > gDio_Info[Dio_num].Xe || (x + x_date) < gDio_Info[Dio_num].Xs || y > gDio_Info[Dio_num].Ye || (y + high) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(x > gAio_Info[Aio_num].Xe || (x + x_date) < gAio_Info[Aio_num].Xs || y > gAio_Info[Aio_num].Ye || (y + high) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(x > gGBKio_Info[GBKio_num].Xe || (x + x_date) < gGBKio_Info[GBKio_num].Xs || y > gGBKio_Info[GBKio_num].Ye || (y + high) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}
		
		x_date = 0;

		for (i = 0; i <= cnt; i++)
		{
			if (id_start + ID[i] >= addr_index[11])
				continue; // ICON is available
			LT_ReadFlash(buff, addr_index[10] + 12 * (id_start + ID[i]), 12);
			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];

			// Record the height and flag of the first valid ICON, and the following ICON arrangement shall be subject to this
			if (i == 0)
			{
				high = pic_h;
				flag = pic_flag;
			}

			if (pic_len != 0 && pic_flag != 0xFF) // ICON is not empty
			{
				if (flag == 0)
					LT268_TFT_ShowPicture(x + x_date, y, pic_w, high, pic_add);
				else if (flag == 1)
					LT268_TFT_ShowPicture_Png(x + x_date, y, pic_w, high, pic_add);
				else if (flag == 2)
					LT268_TFT_ShowPicture_Png_Pixel(x + x_date, y, pic_w, high, pic_add);

				x_date += pic_w;
			}
		}

		if (status) // In order to remove the residual content in the tail
		{
			LT268_dispaly_CutPicture(x + x_date, y,
									 x + x_date, y, RTC_BLANK, high,
									 LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
		}

		/* Display time*/
		num = 0;
		if ((calendar.hour / 10 % 10) == 0)
			num--; // The number of digits is different
		else
			ID[num] = (calendar.hour) / 10 % 10;
		ID[num + 1] = (calendar.hour) % 10;
		ID[num + 2] = 10;
		ID[num + 3] = (calendar.min) / 10 % 10;
		ID[num + 4] = (calendar.min) % 10;
		ID[num + 5] = 10;
		ID[num + 6] = (calendar.sec) / 10 % 10;
		ID[num + 7] = (calendar.sec) % 10;
		cnt = num + 7;

		x = x + x_date + RTC_BLANK; // Pixel interval between time and date

		// display
		for (i = 0; i <= cnt; i++)
		{
			if (id_start + ID[i] >= addr_index[11])
				continue; // ICON is available
			LT_ReadFlash(buff, addr_index[10] + 12 * (id_start + ID[i]), 12);

			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];
			
			if (i == 0) // Record the height and flag of the first valid ICON, and the following ICON arrangement shall be subject to this
			{
				high = pic_h;
				flag = pic_flag;
			}
			
			if (pic_len != 0 && pic_flag != 0xFF) // ICON is not empty
			{
				if (flag == 0)
					LT268_TFT_ShowPicture(x + x_time, y, pic_w, high, pic_add);
				else if (flag == 1)
					LT268_TFT_ShowPicture_Png(x + x_time, y, pic_w, high, pic_add);
				else if (flag == 2)
					LT268_TFT_ShowPicture_Png_Pixel(x + x_time, y, pic_w, high, pic_add);
				x_time += pic_w;
			}
		}

		if (gRTC->Len_last > (x_date + RTC_BLANK + x_time) && status) // In order to remove the residual content in the tail
		{
			LT268_dispaly_CutPicture(x + x_time, y,
									 x + x_time, y, gRTC->Len_last - (x_date + RTC_BLANK + x_time), high,
									 LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
		}
		gRTC->Len_last = x_date + RTC_BLANK + x_time; // Record width
	}
	else if ((mode >= 1 && mode <= 6) || (mode >= 9 && mode <= 11))
	{
		if (mode == 1 || mode == 9)
		{
			num = 0;
			if (calendar.w_year / 1000)
				num = 0;
			else
			{
				num--;
				if ((calendar.w_year / 100 % 10) == 0)
				{
					num--;
					if ((calendar.w_year / 10 % 10) == 0)
						num--;
				}
			}

			if (num >= 0)
				ID[num] = (calendar.w_year) / 1000;
			if (num + 1 >= 0)
				ID[num + 1] = (calendar.w_year) / 100 % 10;
			if (num + 2 >= 0)
				ID[num + 2] = (calendar.w_year) / 10 % 10;
			if (num + 3 >= 0)
				ID[num + 3] = (calendar.w_year) % 10;

			ID[num + 4] = 11;

			if ((calendar.w_month / 10 % 10) == 0)
				num--;
			else
				ID[num + 5] = calendar.w_month / 10 % 10;

			ID[num + 6] = (calendar.w_month) % 10;
			ID[num + 7] = 12;

			if ((calendar.w_date / 10 % 10) == 0)
				num--;
			else
				ID[num + 8] = calendar.w_date / 10 % 10;

			ID[num + 9] = calendar.w_date % 10;

			if (mode == 1)
				cnt = num + 9;
			else
			{
				ID[num + 10] = 13;
				cnt = num + 10;
			}
		}
		else if (mode == 2 || mode == 10)
		{
			num = 0;
			if (calendar.w_year / 1000)
				num = 0;
			else
			{
				num--;
				if ((calendar.w_year / 100 % 10) == 0)
				{
					num--;
					if ((calendar.w_year / 10 % 10) == 0)
						num--;
				}
			}

			if (num >= 0)
				ID[num] = calendar.w_year / 1000;
			if (num + 1 >= 0)
				ID[num + 1] = calendar.w_year / 100 % 10;
			if (num + 2 >= 0)
				ID[num + 2] = calendar.w_year / 10 % 10;
			if (num + 3 >= 0)
				ID[num + 3] = calendar.w_year % 10;

			ID[num + 4] = 11;

			if ((calendar.w_month / 10 % 10) == 0)
				num--;
			else
				ID[num + 5] = calendar.w_month / 10 % 10;

			ID[num + 6] = calendar.w_month % 10;

			if (mode == 2)
				cnt = num + 6;
			else
			{
				ID[num + 7] = 12;
				cnt = num + 7;
			}
		}
		else if (mode == 3 || mode == 11)
		{
			num = 0;
			if ((calendar.w_month / 10 % 10) == 0)
				num--;
			else
				ID[num] = calendar.w_month / 10 % 10;

			ID[num + 1] = calendar.w_month % 10;
			ID[num + 2] = 12;

			if ((calendar.w_date / 10 % 10) == 0)
				num--;
			else
				ID[num + 3] = calendar.w_date / 10 % 10;

			ID[num + 4] = calendar.w_date % 10;

			if (mode == 3)
				cnt = num + 4;
			else
			{
				ID[num + 5] = 13;
				cnt = num + 5;
			}
		}
		else if (mode == 4)
		{
			num = 0;
			if ((calendar.hour / 10 % 10) == 0)
				num--;
			else
				ID[num] = calendar.hour / 10 % 10;
			ID[num + 1] = calendar.hour % 10;
			ID[num + 2] = 10;
			ID[num + 3] = calendar.min / 10 % 10;
			ID[num + 4] = calendar.min % 10;
			ID[num + 5] = 10;
			ID[num + 6] = calendar.sec / 10 % 10;
			ID[num + 7] = calendar.sec % 10;
			cnt = num + 7;
		}
		else if (mode == 5)
		{
			num = 0;
			if ((calendar.hour / 10 % 10) == 0)
				num--;
			else
				ID[num] = calendar.hour / 10 % 10;
			ID[num + 1] = calendar.hour % 10;
			ID[num + 2] = 10;
			ID[num + 3] = calendar.min / 10 % 10;
			ID[num + 4] = calendar.min % 10;
			cnt = num + 4;
		}
		else if (mode == 6)
		{
			num = 0;
			ID[num] = calendar.min / 10 % 10;
			ID[num + 1] = calendar.min % 10;
			ID[num + 2] = 10;
			ID[num + 3] = calendar.sec / 10 % 10;
			ID[num + 4] = calendar.sec % 10;
			cnt = num + 4;
		}
		
		for (i = 0; i <= cnt; i++)
		{
			if (id_start + ID[i] >= addr_index[11])
				continue;

			LT_ReadFlash(buff, addr_index[10] + 12 * (id_start + ID[i]), 12);
			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];
			
			if (i == 0)
			{
				high = pic_h;
				flag = pic_flag;
			}
			if (pic_len != 0 && pic_flag != 0xFF)
			{
				x_time += pic_w;
			}
		}
		
		if (DioKb_flag == 1)
		{
			if (!(x > gDio_Info[Dio_num].Xe || (x + x_time) < gDio_Info[Dio_num].Xs || y > gDio_Info[Dio_num].Ye || (y + high) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(x > gAio_Info[Aio_num].Xe || (x + x_time) < gAio_Info[Aio_num].Xs || y > gAio_Info[Aio_num].Ye || (y + high) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(x > gGBKio_Info[GBKio_num].Xe || (x + x_time) < gGBKio_Info[GBKio_num].Xs || y > gGBKio_Info[GBKio_num].Ye || (y + high) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}
		
		x_time = 0;

		for (i = 0; i <= cnt; i++)
		{
			if (id_start + ID[i] >= addr_index[11])
				continue;

			LT_ReadFlash(buff, addr_index[10] + 12 * (id_start + ID[i]), 12);
			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];

			if (i == 0)
			{
				high = pic_h;
				flag = pic_flag;
			}

			if (pic_len != 0 && pic_flag != 0xFF)
			{
				if (flag == 0)
					LT268_TFT_ShowPicture(x + x_time, y, pic_w, pic_h, pic_add);
				else if (flag == 1)
					LT268_TFT_ShowPicture_Png(x + x_time, y, pic_w, pic_h, pic_add);
				else if (flag == 2)
					LT268_TFT_ShowPicture_Png_Pixel(x + x_time, y, pic_w, pic_h, pic_add);
				x_time += pic_w;
			}
		}

		if (gRTC->Len_last > x_time && status)
		{
			LT268_dispaly_CutPicture(x + x_time, y,
									 x + x_time, y, gRTC->Len_last - x_time, high,
									 LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
		}
		gRTC->Len_last = x_time;
	}
	else if (mode == 7) // week
	{
		ID[0] = 14 + calendar.week;

		if (id_start + ID[0] < addr_index[11])
		{
			LT_ReadFlash(buff, addr_index[10] + 12 * (id_start + ID[0]), 12);

			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];

			if (DioKb_flag == 1)
			{
				if (!(x > gDio_Info[Dio_num].Xe || (x + pic_w) < gDio_Info[Dio_num].Xs || y > gDio_Info[Dio_num].Ye || (y + pic_h) < gDio_Info[Dio_num].Ys))
				{
					return 0;
				}
			}
			else if (AioKb_flag == 1)
			{
				if (!(x > gAio_Info[Aio_num].Xe || (x + pic_w) < gAio_Info[Aio_num].Xs || y > gAio_Info[Aio_num].Ye || (y + pic_h) < gAio_Info[Aio_num].Ys))
				{
					return 0;
				}
			}
			else if (GBKioKb_flag == 1)
			{
				if (!(x > gGBKio_Info[GBKio_num].Xe || (x + pic_w) < gGBKio_Info[GBKio_num].Xs || y > gGBKio_Info[GBKio_num].Ye || (y + pic_h) < gGBKio_Info[GBKio_num].Ys))
				{
					return 0;
				}
			}

			if (pic_len != 0 && pic_flag != 0xFF)
			{

				if (pic_flag == 0)
				{
					LT268_TFT_ShowPicture(x, y, pic_w, pic_h, pic_add);
				}
				else if (pic_flag == 1)
				{
					LT268_TFT_ShowPicture_Png(x, y, pic_w, pic_h, pic_add);
				}
				else if (pic_flag == 2)
				{
					LT268_TFT_ShowPicture_Png_Pixel(x, y, pic_w, pic_h, pic_add);
				}
			}
		}
	}
}

/***********************************************************************************
* Function Name : RTC_display
* Description   : Get digital clock info.
* Input         : - type: digital clock info sources
				  - buff: digital clock info
* Output        : None
* Return        : None
************************************************************************************/
void RTC_display(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, p_len, pointer;
	uint16_t x, y, w, h; // Display box
	uint16_t simage, eimage;
	uint8_t mode = 0;

	if (type == 0) // instruction information source is configuration file
	{
		x = buff[5] + (buff[6] << 8);
		y = buff[7] + (buff[8] << 8);
		simage = buff[9] + (buff[10] << 8);
		eimage = buff[11] + (buff[12] << 8);
		mode = buff[13];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		x = buff[pointer] + (buff[pointer + 1] << 8);
		y = buff[pointer + 2] + (buff[pointer + 3] << 8);
		simage = buff[pointer + 4] + (buff[pointer + 5] << 8);
		eimage = buff[pointer + 6] + (buff[pointer + 7] << 8);
		mode = buff[pointer + 7];
	}

	gRTC_Info[RTC_num].x = x;
	gRTC_Info[RTC_num].y = y;
	gRTC_Info[RTC_num].ID_start = simage;
	gRTC_Info[RTC_num].mode = mode;

	if (Pop_up_flag == 1)
	{
		gRTC_Info[RTC_num].x += Pop_up_x;
		gRTC_Info[RTC_num].y += Pop_up_y;
	}

	Display_RTC(&gRTC_Info[RTC_num], 0);
	RTC_num++;
}

void show_RTC(void)
{
	if (RTC_num > 0 && RTC_flag == 1)
	{
		RTC_flag = 0;
		for (uint8_t i = 0; i < RTC_num; i++)
		{
			Display_RTC(&gRTC_Info[i], 1);
		}
	}
}

uint8_t Clock_num = 0;
uint8_t Clock_flag = 0;
Clock_Info gClock_Info[CLOCK_SIZE];
uint32_t Lay_temp = 0;
/***********************************************************************************
* Function Name : Display_Clock
* Description   : Show analog clock.
* Input         : - num: analog clock number
				  - status: analog clock status
* Output        : None
* Return        : None
************************************************************************************/
uint8_t Display_Clock(uint8_t num, uint8_t status)
{
	uint8_t hour, min, sec;
	uint8_t hour_temp;

	hour = calendar.hour;
	min = calendar.min;
	sec = calendar.sec;

	hour = hour % 12;

	if (gClock_Info[num].Image_BG < addr_index[11]) // ICON is available
	{
		if (gClock_Info[num].len_pic != 0 && gClock_Info[num].flag_pic != 0xFF) // ICON is not empty
		{
			// In the keyboard input interface
			if (DioKb_flag == 1)
			{
				if (!(gClock_Info[num].x_pic > gDio_Info[Dio_num].Xe || (gClock_Info[num].x_pic + gClock_Info[num].w_pic) < gDio_Info[Dio_num].Xs || gClock_Info[num].y_pic > gDio_Info[Dio_num].Ye || (gClock_Info[num].y_pic + gClock_Info[num].h_pic) < gDio_Info[Dio_num].Ys))
				{
					return 0;
				}
			}
			else if (AioKb_flag == 1)
			{
				if (!(gClock_Info[num].x_pic > gAio_Info[Aio_num].Xe || (gClock_Info[num].x_pic + gClock_Info[num].w_pic) < gAio_Info[Aio_num].Xs || gClock_Info[num].y_pic > gAio_Info[Aio_num].Ye || (gClock_Info[num].y_pic + gClock_Info[num].h_pic) < gAio_Info[Aio_num].Ys))
				{
					return 0;
				}
			}
			else if (GBKioKb_flag == 1)
			{
				if (!(gClock_Info[num].x_pic > gGBKio_Info[GBKio_num].Xe || (gClock_Info[num].x_pic + gClock_Info[num].w_pic) < gGBKio_Info[GBKio_num].Xs || gClock_Info[num].y_pic > gGBKio_Info[GBKio_num].Ye || (gClock_Info[num].y_pic + gClock_Info[num].h_pic) < gGBKio_Info[GBKio_num].Ys))
				{
					return 0;
				}
			}

			// full-screen background
			if (gClock_Info[num].flag_pic == 1 || gClock_Info[num].flag_pic == 2)
			{

				LT268_pic_to_buffer(0, 0, gClock_Info[num].w_pic, m_PngData,
									gClock_Info[num].x_pic, gClock_Info[num].y_pic, LCD_XSIZE_TFT, FullScreen_addr,
									gClock_Info[num].w_pic, gClock_Info[num].h_pic, FullScreen_flag);
			}

			// clock background
			LT268_pic_to_buffer(0, 0, gClock_Info[num].w_pic, m_PngData,
								0, 0, gClock_Info[num].w_pic, gClock_Info[num].addr_pic,
								gClock_Info[num].w_pic, gClock_Info[num].h_pic, gClock_Info[num].flag_pic);

			// Pointer of clock
			DrawClockPointer(gClock_Info[num].x, gClock_Info[num].y, hour * 30 + min * 30 / 60, gClock_Info[num].L_hour, gClock_Info[num].S_hour, gClock_Info[num].Color_hour, gClock_Info[num].W_hour,
							 gClock_Info[num].x, gClock_Info[num].y, min * 6 + sec * 6 / 60, gClock_Info[num].L_min, gClock_Info[num].S_min, gClock_Info[num].Color_min, gClock_Info[num].W_min, // min*6+sec*6/60
							 gClock_Info[num].x, gClock_Info[num].y, sec * 6, gClock_Info[num].L_sec, gClock_Info[num].S_sec, gClock_Info[num].Color_sec, gClock_Info[num].W_sec,
							 gClock_Info[num].x_pic, gClock_Info[num].y_pic, gClock_Info[num].w_pic, gClock_Info[num].h_pic);

			// center ICON
			if (gClock_Info[num].len_cen != 0 && gClock_Info[num].flag_cen != 0xFF)
			{
				pic_flag = gClock_Info[num].flag_cen;

				LT268_pic_to_buffer(gClock_Info[num].x_cen - gClock_Info[num].x_pic, gClock_Info[num].y_cen - gClock_Info[num].y_pic, gClock_Info[num].w_pic, m_PngData,
									0, 0, gClock_Info[num].w_cen, gClock_Info[num].addr_cen,
									gClock_Info[num].w_cen, gClock_Info[num].h_cen, gClock_Info[num].flag_cen);
			}

			LT268_buffer_to_TFT(0, 0, gClock_Info[num].w_pic, m_PngData,
								gClock_Info[num].x_pic, gClock_Info[num].y_pic, gClock_Info[num].w_pic, gClock_Info[num].h_pic);
		}
	}
}

/***********************************************************************************
* Function Name	: Clock_display
* Description   : Get analog clock info.
* Input         : - type: analog clock info sources
				  - buff: analog clock info
* Output        : None
* Return        : None
************************************************************************************/
void Clock_display(uint8_t type, uint8_t *buff)
{
	uint8_t buff1[12] = {0};
	uint8_t L_hour, S_hour, W_hour, L_min, S_min, W_min, L_sec, S_sec, W_sec;
	uint16_t p_add, p_len, pointer;
	uint16_t x, y, image, image_cen;
	uint16_t r, g, b;
	uint32_t Color_hour = 0, Color_min = 0, Color_sec = 0;
	if (type == 0) // Instruction information source is configuration file
	{
		x = buff[5] + (buff[6] << 8);
		y = buff[7] + (buff[8] << 8);
		image = buff[9] + (buff[10] << 8);
		L_hour = buff[11];
		S_hour = buff[12];
		W_hour = buff[13];
		Color_hour = buff[14] + (buff[15] << 8) + (buff[16] << 16);
		L_min = buff[17];
		S_min = buff[18];
		W_min = buff[19];
		Color_min = buff[20] + (buff[21] << 8) + (buff[22] << 16);
		L_sec = buff[23];
		S_sec = buff[24];
		W_sec = buff[25];
		Color_sec = buff[26] + (buff[27] << 8) + (buff[28] << 16);
		image_cen = buff[29] + (buff[30] << 8);
	}
	else if (type == 1) // Instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		x = buff[pointer] + (buff[pointer + 1] << 8);
		y = buff[pointer + 2] + (buff[pointer + 3] << 8);
	}
	
	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}
	gClock_Info[Clock_num].x_pic = x;
	gClock_Info[Clock_num].y_pic = y;
	gClock_Info[Clock_num].Image_BG = image;
	gClock_Info[Clock_num].L_hour = L_hour;
	gClock_Info[Clock_num].S_hour = S_hour;
	gClock_Info[Clock_num].W_hour = W_hour;
	gClock_Info[Clock_num].Color_hour = Color_hour;
	gClock_Info[Clock_num].L_min = L_min;
	gClock_Info[Clock_num].S_min = S_min;
	gClock_Info[Clock_num].W_min = W_min;
	gClock_Info[Clock_num].Color_min = Color_min;
	gClock_Info[Clock_num].L_sec = L_sec;
	gClock_Info[Clock_num].S_sec = S_sec;
	gClock_Info[Clock_num].W_sec = W_sec;
	gClock_Info[Clock_num].Color_sec = Color_sec;

	if (image < addr_index[11]) // ICON is not empty
	{
		LT_ReadFlash(buff1, addr_index[10] + 12 * image, 12);

		gClock_Info[Clock_num].addr_pic = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		gClock_Info[Clock_num].w_pic = buff1[4] + (buff1[5] << 8);
		gClock_Info[Clock_num].h_pic = buff1[6] + (buff1[7] << 8);
		gClock_Info[Clock_num].len_pic = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		gClock_Info[Clock_num].flag_pic = buff1[11];
		gClock_Info[Clock_num].x = x + gClock_Info[Clock_num].w_pic / 2;
		gClock_Info[Clock_num].y = y + gClock_Info[Clock_num].h_pic / 2;

		if (image_cen < addr_index[11]) // ICON is not empty
		{
			LT_ReadFlash(buff1, addr_index[10] + 12 * image_cen, 12);

			gClock_Info[Clock_num].addr_cen = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			gClock_Info[Clock_num].w_cen = buff1[4] + (buff1[5] << 8);
			gClock_Info[Clock_num].h_cen = buff1[6] + (buff1[7] << 8);
			gClock_Info[Clock_num].len_cen = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
			gClock_Info[Clock_num].flag_cen = buff1[11];
			gClock_Info[Clock_num].x_cen = gClock_Info[Clock_num].x - gClock_Info[Clock_num].w_cen / 2;
			gClock_Info[Clock_num].y_cen = gClock_Info[Clock_num].y - gClock_Info[Clock_num].h_cen / 2;
		}
	}

	Display_Clock(Clock_num, 0);
	Clock_num++;
	
}

void show_Clock(void)
{
	if (Clock_num > 0 && Clock_flag == 1)
	{
		Clock_flag = 0;
		for (uint8_t i = 0; i < Clock_num; i++)
		{
			Display_Clock(i, 1);
		}
	}
}

/*******************************************************************************
 * Function Name : LT_Print_zk_Font_Scroll
 * Description   : txt scroll.
 * Input         :
 * Output        : None
 * Return        : None
 ********************************************************************/
uint16_t LT_Print_zk_Font_Scroll(
	uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size //  font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	,
	uint8_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	,
	_PICINFO mixpic // mix picture info
	,
	uint16_t Xs // Text box start x position
	,
	uint16_t Ys // Text box start Y position
	,
	uint16_t Xe // Text box end x position
	,
	uint16_t Ye // Text box end y position
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
	,
	uint16_t num // Scroll_num
	,
	uint16_t x_off // x offset
)
{
	uint16_t temp = 0, temp_H = 0, temp_L = 0;
	uint32_t i = 0;
	uint16_t X_start = 0, Y_start = 0;
	uint8_t gray, gray_bit;
	uint16_t disp_w = 0, disp_i = 0;
	uint16_t temp_w;
	uint16_t box_w = Xe - Xs + 1, box_h = Ye - Ys + 1;
	uint16_t buf_w = 0, buf_h = Ye - Ys + 1;
	uint8_t unicode_w;
	uint16_t font_byte; // bytes of a single font
	
	LT_ReadFlash(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash(&gray, FlashAddr + 8, 1);
	
	if (gray == 0)
		gray_bit = 1;
	else if (gray == 1)
		gray_bit = 2;
	else if (gray == 2)
		gray_bit = 4;
	font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;

	i = 0;
	if (encode == 4) // ASCII
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else
				break;
		}
	}
	else if (encode == 0)
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += Ascii_w[c[i] - 0x20] + dis_x + 2;
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 1)
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 2)
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 3)
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1)
		{
			unicode = (c[i] << 8) + c[i + 1];
			if (unicode < 128 && unicode > 0x00)
			{
				buf_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 6)
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1)
		{
			unicode = (c[i] << 8) + c[i + 1];
			if (unicode < 128 && unicode > 0x00)
			{
				buf_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				buf_w += (unicode_w + dis_x);
				i += 2;
			}
			else
				break;
		}
	}

	if (buf_w > box_w)
	{
		buf_w = buf_w + gScroll_Info[num].gap;
		gScroll_Info[num].flag = 1;
	}
	else if (buf_w + gScroll_Info[num].gap > box_w)
	{
		buf_w = box_w + gScroll_Info[num].gap;
		gScroll_Info[num].flag = 1;
	}
	else
	{
		if (gScroll_Info[num].scroll_en)
		{
			buf_w = box_w + gScroll_Info[num].gap;
			gScroll_Info[num].flag = 1;
		}
		else
		{
			if (Alignment == 0)
				X_start = 0;
			else if (Alignment == 1)
				X_start = (box_w - buf_w) / 2;
			else if (Alignment == 2)
				X_start = box_w - buf_w;

			buf_w = box_w;
			gScroll_Info[num].flag = 0;
		}
	}

	if (buf_w * buf_h * 2 > MAX_PixelSize)
		return 1;

	LT_ReadFlash(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash(&gray, FlashAddr + 8, 1);

	gScroll_Info[num].buf_w = buf_w;
	//	printf("buf_w,buf_h,box_w,box_h    %d    %d   %d   %d    \r\n",buf_w,buf_h,box_w,box_h);
	//	printf("x_off  gScroll_Info[num].w   %d    %d   %d   %d    \r\n \r\n",x_off,gScroll_Info[num].w,box_w,box_h);

	if ((x_off + box_w) <= buf_w)
	{
		if (enbackcolor)
		{
			LT268_TFT_FillColor_Buffer2(0, 0, buf_w, m_PngData, buf_w, box_h, BackColor);
			//			debug
			//			if(x_off > 0)
			//			LT268_pic_to_buffer(buf_w - box_w, 0, buf_w, m_PngData,
			//								Xs + , Ys, LCD_XSIZE_TFT, FullScreen_addr,
			//								buf_w - x_off, box_h, 0);
		}
		else
		{
			if (mix == 0)
			{
				LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData, Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr, box_w, box_h, 0);
			}
			else
			{
				if (mixpic.flag == 0x10)
					LT268_TFT_FillColor_Buffer2(0, 0, buf_w, m_PngData, buf_w, box_h, mixpic.len);
				else
				{
					if (mixpic.flag != 0)
						LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData, Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr, box_w, box_h, 0);
					LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData, Xs - mixpic.x, Ys - mixpic.y, mixpic.w, mixpic.addr, box_w, box_h, mixpic.flag);
				}
			}
		}
	}
	else
	{
		if (enbackcolor)
		{
			LT268_TFT_FillColor_Buffer2(0, 0, buf_w, m_PngData, buf_w, box_h, BackColor);
			//			debug
			//			LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData,
			//								Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr,
			//								buf_w - x_off, box_h, 0);
			//			LT268_pic_to_buffer(0, 0, buf_w, m_PngData,
			//								Xs + buf_w - x_off, Ys, LCD_XSIZE_TFT, FullScreen_addr,
			//								box_w - (buf_w - x_off), box_h, 0);
		}
		else
		{
			if (mix == 0)
			{
				LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData, Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr, buf_w - x_off, box_h, 0);
				LT268_pic_to_buffer(0, 0, buf_w, m_PngData, Xs + buf_w - x_off, Ys, LCD_XSIZE_TFT, FullScreen_addr, box_w - (buf_w - x_off), box_h, 0);
			}
			else
			{
				if (mixpic.flag == 0x10)
					LT268_TFT_FillColor_Buffer2(0, 0, buf_w, m_PngData, buf_w, box_h, mixpic.len);
				else
				{
					if (mixpic.flag != 0)
					{
						LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData, Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr, buf_w - x_off, box_h, 0);
						LT268_pic_to_buffer(0, 0, buf_w, m_PngData, Xs + buf_w - x_off, Ys, LCD_XSIZE_TFT, FullScreen_addr, box_w - (buf_w - x_off), box_h, 0);
					}
					LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData, Xs - mixpic.x, Ys - mixpic.y, mixpic.w, mixpic.addr, buf_w - x_off, box_h, mixpic.flag);
					LT268_pic_to_buffer(0, 0, buf_w, m_PngData, Xs - mixpic.x + buf_w - x_off, Ys - mixpic.y, mixpic.w, mixpic.addr, box_w - (buf_w - x_off), box_h, mixpic.flag);
				}
			}
		}
	}

	i = 0;

	if (encode == 4) // ASCII
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{

			if (c[i] < 128 && c[i] > 0x00)
				temp_w = (Ascii_w[c[i] - 0x20] + dis_x + 2);
			// else if(c[i]==0x0A)                temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i; disp_i++)
				{
					LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
													FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
													X_start, Y_start, buf_w, m_PngData);

					X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
		}
	}
	else if (encode == 0) // GB2312
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			// else if(c[i]==0x0A)                temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i] != 0xFF)
					{
						LT268_GrayScaleFont_dislay_BUFF(0, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 1) // GBK
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			// else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0x81 && c[disp_i + 1] >= 0x40 && c[disp_i] != 0xFF)
					{

						LT268_GrayScaleFont_dislay_BUFF(1, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 2) // BIG
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
				temp_w = W_Size + dis_x;
			// else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i + 1] >= 0x40)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 3)
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
				temp_w = W_Size + dis_x;
			// else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code),
														X_start, Y_start, buf_w, m_PngData);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i++;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 6)
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				temp_w = unicode_w + dis_x;
			}
			// else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code),
														X_start, Y_start, buf_w, m_PngData);

						LT_ReadFlash(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode_temp - start_code) * (font_byte + 1), 1);

						X_start += (unicode_w + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i++;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += temp_w;
				i += 2;
			}
		}
	}
	return 0;
}

uint8_t Scroll_num = 0;
uint8_t Scroll_flag = 0;
Scroll_Info gScroll_Info[SCROLL_SIZE];
/***********************************************************************************
* Function Name	: text_scroll
* Description	: Get text scroll info.
* Input         : - type: text scroll info sources
				  - buff: text scroll info
* Output        : None
* Return        : None
************************************************************************************/
void text_scroll(uint8_t type, uint8_t *buff)
{
	uint16_t xs, ys, xe, ye; // Display box
	uint8_t Zk_id, w, h;	 // Font ID, font width and height
	uint8_t encode;			 // Font encoding type
	uint8_t Alignment;
	uint32_t fcolor, bcolor; // The foreground color of the font,The background color of the font
	uint16_t p_add, p_len, pointer;
	uint32_t zk_addr;
	uint8_t buff1[4] = {0};
	uint8_t scroll_en = 0;
	uint8_t t_d = 0;
	uint16_t gap = 0;
	uint8_t transparent = 0;

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8)) * 2;
		p_len = buff[15] + (buff[16] << 8);
		xs = buff[7] + (buff[8] << 8);
		ys = buff[9] + (buff[10] << 8);
		xe = buff[11] + (buff[12] << 8);
		ye = buff[13] + (buff[14] << 8);
		Zk_id = buff[17];
		w = buff[18];
		h = buff[19];
		encode = buff[20];
		Alignment = buff[21];
		scroll_en = buff[22];
		fcolor = buff[23] + (buff[24] << 8) + (buff[25] << 16);
		t_d = buff[26];
		bcolor = buff[27] + (buff[28] << 8) + (buff[29] << 16);
		gap = buff[30] + (buff[31] << 8);
		transparent = buff[32];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer] + (var[pointer + 1] << 8)) * 2;
		p_len = var[pointer + 10] + (var[pointer + 11] << 8);
		xs = var[pointer + 2] + (var[pointer + 3] << 8);
		ys = var[pointer + 4] + (var[pointer + 5] << 8);
		xe = var[pointer + 6] + (var[pointer + 7] << 8);
		ye = var[pointer + 8] + (var[pointer + 9] << 8);
		Zk_id = var[pointer + 12];
		w = var[pointer + 13];
		h = var[pointer + 14];
		encode = var[pointer + 15];
		Alignment = var[pointer + 16];
		scroll_en = var[pointer + 17];
		fcolor = var[pointer + 18] + (var[pointer + 19] << 8) + (var[pointer + 20] << 16);
		t_d = var[pointer + 21];
		bcolor = var[pointer + 22] + (var[pointer + 23] << 8) + (var[pointer + 24] << 16);
		gap = var[pointer + 25] + (var[pointer + 26] << 8);
		transparent = var[pointer + 27];
	}
	
	if (Pop_up_flag == 1) // Popup offset
	{
		xs += Pop_up_x;
		ys += Pop_up_y;
		xe += Pop_up_x;
		ye += Pop_up_y;
	}
	
	LT_ReadFlash(buff1, addr_index[2] + Zk_id * 8, 4);
	zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);

	gScroll_Info[Scroll_num].x = xs;
	gScroll_Info[Scroll_num].y = ys;
	gScroll_Info[Scroll_num].w = xe - xs + 1;
	gScroll_Info[Scroll_num].h = ye - ys + 1;
	gScroll_Info[Scroll_num].t_d = t_d;
	// gScroll_Info[Scroll_num].cnt = gScroll_Info[Scroll_num].w;
	gScroll_Info[Scroll_num].cnt = 0;
	gScroll_Info[Scroll_num].t_c = 0;
	gScroll_Info[Scroll_num].gap = gap;
	gScroll_Info[Scroll_num].transparent = transparent;
	gScroll_Info[Scroll_num].scroll_en = scroll_en;
	gScroll_Info[Scroll_num].bcolor = bcolor;
	gScroll_Info[Scroll_num].encode = encode;
	gScroll_Info[Scroll_num].zk_addr = zk_addr;
	gScroll_Info[Scroll_num].fcolor = fcolor;
	gScroll_Info[Scroll_num].Alignment = Alignment;
	gScroll_Info[Scroll_num].xe = xe;
	gScroll_Info[Scroll_num].ye = ye;
	gScroll_Info[Scroll_num].len_max = p_len * 2;
	gScroll_Info[Scroll_num].c = &var[p_add];
	gScroll_Info[Scroll_num].font_w = w;
	gScroll_Info[Scroll_num].font_h = h;

	LT_Print_zk_Font_Scroll(encode, zk_addr,
							LAY_BUFF1, LCD_XSIZE_TFT, w, h, Alignment, fcolor, bcolor, transparent, 0, PICINFO[0],
							xs, ys, xe, ye,
							0, 0, gScroll_Info[Scroll_num].c, p_len * 2,
							Scroll_num, 0);

//	LT268_buffer_to_TFT(0, 0, gScroll_Info[Scroll_num].buf_w, m_PngData,
//						gScroll_Info[Scroll_num].x, gScroll_Info[Scroll_num].y, gScroll_Info[Scroll_num].w, gScroll_Info[Scroll_num].h);
}

uint8_t text_scroll_Once(uint8_t num)
{
	// In the keyboard input interface
	if (DioKb_flag == 1)
	{
		if (!(gScroll_Info[num].x > gDio_Info[Dio_num].Xe || (gScroll_Info[num].x + gScroll_Info[num].w) < gDio_Info[Dio_num].Xs ||
			  gScroll_Info[num].y > gDio_Info[Dio_num].Ye || (gScroll_Info[num].y + gScroll_Info[num].h) < gDio_Info[Dio_num].Ys))
		{
			return 0;
		}
	}
	else if (AioKb_flag == 1)
	{
		if (!(gScroll_Info[num].x > gAio_Info[Aio_num].Xe || (gScroll_Info[num].x + gScroll_Info[num].w) < gAio_Info[Aio_num].Xs ||
			  gScroll_Info[num].y > gAio_Info[Aio_num].Ye || (gScroll_Info[num].y + gScroll_Info[num].h) < gAio_Info[Aio_num].Ys))
		{
			return 0;
		}
	}
	else if (GBKioKb_flag == 1)
	{
		if (!(gScroll_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gScroll_Info[num].x + gScroll_Info[num].w) < gGBKio_Info[GBKio_num].Xs ||
			  gScroll_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gScroll_Info[num].y + gScroll_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
		{
			return 0;
		}
	}

	if (gScroll_Info[num].cnt + gScroll_Info[num].w <= gScroll_Info[num].buf_w)
	{
		LT_Print_zk_Font_Scroll(gScroll_Info[num].encode, gScroll_Info[num].zk_addr,
								LAY_BUFF1, LCD_XSIZE_TFT, gScroll_Info[num].font_w, gScroll_Info[num].font_h, gScroll_Info[num].Alignment,
								gScroll_Info[num].fcolor, gScroll_Info[num].bcolor, gScroll_Info[num].transparent, 0, PICINFO[0],
								gScroll_Info[num].x, gScroll_Info[num].y, gScroll_Info[num].xe, gScroll_Info[num].ye,
								0, 0, gScroll_Info[num].c, gScroll_Info[num].len_max,
								num, gScroll_Info[num].cnt);

		LT268_buffer_to_TFT(gScroll_Info[num].cnt, 0, gScroll_Info[num].buf_w, m_PngData,
							gScroll_Info[num].x, gScroll_Info[num].y, gScroll_Info[num].w, gScroll_Info[num].h);
	}
	else
	{
		LT_Print_zk_Font_Scroll(gScroll_Info[num].encode, gScroll_Info[num].zk_addr,
								LAY_BUFF1, LCD_XSIZE_TFT, gScroll_Info[num].font_w, gScroll_Info[num].font_h, gScroll_Info[num].Alignment,
								gScroll_Info[num].fcolor, gScroll_Info[num].bcolor, gScroll_Info[num].transparent, 0, PICINFO[0],
								gScroll_Info[num].x, gScroll_Info[num].y, gScroll_Info[num].xe, gScroll_Info[num].ye,
								0, 0, gScroll_Info[num].c, gScroll_Info[num].len_max,
								num, gScroll_Info[num].cnt);

		LT268_buffer_to_TFT(gScroll_Info[num].cnt, 0, gScroll_Info[num].buf_w, m_PngData,
							gScroll_Info[num].x, gScroll_Info[num].y, gScroll_Info[num].buf_w - gScroll_Info[num].cnt, gScroll_Info[num].h);

		LT268_buffer_to_TFT(0, 0, gScroll_Info[num].buf_w, m_PngData,
							gScroll_Info[num].x + gScroll_Info[num].buf_w - gScroll_Info[num].cnt, gScroll_Info[num].y,
							gScroll_Info[num].w - (gScroll_Info[num].buf_w - gScroll_Info[num].cnt), gScroll_Info[num].h);
	}
	//	printf("gScroll_Info[num].cnt,gScroll_Info[num].buf_w,        %d    %d \r\n",gScroll_Info[num].cnt,gScroll_Info[num].buf_w);

	gScroll_Info[num].cnt += 1;
	if (gScroll_Info[num].cnt >= gScroll_Info[num].buf_w)
		gScroll_Info[num].cnt = 0;
}

void scroll_text(void)
{
	uint8_t i;
	if (Scroll_num && Scroll_flag)
	{
		Scroll_flag = 0;
		for (i = 0; i < Scroll_num; i++)
			gScroll_Info[i].t_c++;
		for (i = 0; i < Scroll_num; i++)
		{
			// When a window timing time expires, scroll 1 pixel
			if ((gScroll_Info[i].t_c >= gScroll_Info[i].t_d) && gScroll_Info[i].flag)
			{
				text_scroll_Once(i);
				gScroll_Info[i].t_c = 0;
			}
		}
	}
}

/***********************************************************************************
* Function Name	: progress_bar
* Description	: Display progress_bar.
* Input			: - type: progress_bar info sources
				  - buff: progress_bar info
* Output        : None
* Return        : None
************************************************************************************/
void progress_bar(uint8_t type, uint8_t *buff)
{
	uint8_t buff1[12] = {0};
	int16_t sum = 0;
	uint16_t w, h;
	uint16_t dw1 = 0, dh1 = 0, bgw, bgh;
	uint16_t pointer, p_add, x2, y2, x1, y1, bar_id, bg_id;
	uint16_t Vmax, Vmin;
	uint8_t dir;

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8));
		x2 = buff[7] + (buff[8] << 8);
		y2 = buff[9] + (buff[10] << 8);
		bar_id = buff[11] + (buff[12] << 8);
		dir = buff[13];
		Vmax = buff[14] + (buff[15] << 8);
		Vmin = buff[16] + (buff[17] << 8);
		x1 = buff[18] + (buff[19] << 8);
		y1 = buff[20] + (buff[21] << 8);
		bg_id = buff[22] + (buff[23] << 8);
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer] + (var[pointer + 1] << 8));
		x2 = buff[pointer + 2] + (buff[pointer + 3] << 8);
		y2 = buff[pointer + 4] + (buff[pointer + 5] << 8);
		bar_id = buff[pointer + 6] + (buff[pointer + 7] << 8);
		dir = buff[pointer + 8];
		Vmax = buff[pointer + 9] + (buff[pointer + 10] << 8);
		Vmin = buff[pointer + 11] + (buff[pointer + 12] << 8);
		x1 = buff[pointer + 13] + (buff[pointer + 14] << 8);
		y1 = buff[pointer + 15] + (buff[pointer + 16] << 8);
		bg_id = buff[pointer + 17] + (buff[pointer + 18] << 8);
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x1 += Pop_up_x;
		y1 += Pop_up_y;
		x2 += Pop_up_x;
		y2 += Pop_up_y;
	}

	if (bar_id == 0xFFFF)
		return;

	if (bg_id != 0xFFFF)
	{
		LT_ReadFlash(buff1, addr_index[10] + 12 * bg_id, 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		bgw = buff1[4] + (buff1[5] << 8);
		bgh = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		// progress_bar background
		if (pic_flag == 1 || pic_flag == 2)
			LT268_pic_to_buffer(0, 0, bgw, m_PngData,
								x1, y1, LCD_XSIZE_TFT, FullScreen_addr,
								bgw, bgh, 0);

		LT268_pic_to_buffer(0, 0, bgw, m_PngData,
							0, 0, bgw, pic_add,
							bgw, bgh, pic_flag);

		// progress_bar picture
		LT_ReadFlash(buff1, addr_index[10] + 12 * bar_id, 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		dw1 = pic_w;
		dh1 = pic_h;
		x2 = x2 - x1;
		y2 = y2 - y1;
	}
	else
	{
		// progress_bar coordinate set 0
		x2 = 0;
		y2 = 0;

		// progress_bar picture
		LT_ReadFlash(buff1, addr_index[10] + 12 * bar_id, 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		bgw = pic_w;
		bgh = pic_h;

		dw1 = pic_w;
		dh1 = pic_h;

		LT268_pic_to_buffer(0, 0, bgw, m_PngData,
							x1, y1, LCD_XSIZE_TFT, FullScreen_addr,
							bgw, bgh, 0);
	}

	switch (dir)
	{
	case 0: // From left to right

		sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		if (sum > Vmax)
			sum = Vmax;
		else if (sum < Vmin)
			sum = Vmin;

		w = dw1 * (sum - Vmin) / (Vmax - Vmin);

		LT268_pic_to_buffer(x2, y2, bgw, m_PngData,
							0, 0, dw1, pic_add,
							w, dh1, pic_flag);

		break;
	case 1: // From right to left

		sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		if (sum > Vmax)
			sum = Vmax;
		else if (sum < Vmin)
			sum = Vmin;

		w = (dw1) * (sum - Vmin) / (Vmax - Vmin);

		LT268_pic_to_buffer(x2 + dw1 - w, y2, bgw, m_PngData,
							dw1 - w, 0, dw1, pic_add,
							w, dh1, pic_flag);

		break;
	case 2: // From top to bottom

		sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		if (sum > Vmax)
			sum = Vmax;
		else if (sum < Vmin)
			sum = Vmin;

		h = dh1 * (sum - Vmin) / (Vmax - Vmin);

		LT268_pic_to_buffer(x2, y2, bgw, m_PngData,
							0, 0, dw1, pic_add,
							dw1, h, pic_flag);

		break;
	case 3: // From bottom to top

		sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		if (sum > Vmax)
			sum = Vmax;
		else if (sum < Vmin)
			sum = Vmin;

		h = dh1 * (sum - Vmin) / (Vmax - Vmin);

		LT268_pic_to_buffer(x2, y2 + dh1 - h, bgw, m_PngData,
							0, dh1 - h, dw1, pic_add,
							dw1, h, pic_flag);
		break;
	default:
		break;
	}

	// display
	LT268_buffer_to_TFT(0, 0, bgw, m_PngData,
						x1, y1, bgw, bgh);
}

/***********************************************************************************
* Function Name	: Circular_progress_bar
* Description	: Display ring progress bar.
* Input         : - type: ring info sources
				  - buff: ring info
* Output        : None
* Return        : None
************************************************************************************/
void Circular_progress_bar(uint8_t type, uint8_t *buff)
{
	uint16_t temp, xd = 0;
	uint8_t buff1[16];
	uint16_t value = 0, ll;
	uint16_t pointer, p_add, x, y, dx, dy, fornt_id, bg_id, Sangle, Eangle;
	uint16_t Vmax, Vmin, S_id, E_id, angle;
	uint8_t I_num, D_num, Alig, zk_id, flag, n = 0, i = 0, kk = 0, flag1 = 0;
	uint32_t color, zk_addr;
	uint16_t xR, yR;
	uint16_t num_w, dot_w, h, canvas_numw, canvas_dotw;
	uint16_t ring_R, ring_CX, ring_CY; // ring radius,centre point

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8));
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		fornt_id = buff[11] + (buff[12] << 8);
		bg_id = buff[13] + (buff[14] << 8);
		Vmin = buff[15] + (buff[16] << 8);
		Vmax = buff[17] + (buff[18] << 8);
		Sangle = buff[19] + (buff[20] << 8);
		Eangle = buff[21] + (buff[22] << 8);
		dx = buff[23] + (buff[24] << 8);
		dy = buff[25] + (buff[26] << 8);
		I_num = buff[27];
		D_num = buff[28];
		Alig = buff[29];
		zk_id = buff[30];
		color = buff[31] + (buff[32] << 8) + (buff[33] << 16);
		S_id = buff[34] + (buff[35] << 8);
		E_id = buff[36] + (buff[37] << 8);
		flag = buff[38];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8));
		p_add = (var[pointer] + (var[pointer + 1] << 8));
		x = buff[pointer + 2] + (buff[pointer + 3] << 8);
		y = buff[pointer + 4] + (buff[pointer + 5] << 8);
		fornt_id = buff[pointer + 6] + (buff[pointer + 7] << 8);
		bg_id = buff[pointer + 8] + (buff[pointer + 9] << 8);
		Vmin = buff[pointer + 10] + (buff[pointer + 11] << 8);
		Vmax = buff[pointer + 12] + (buff[pointer + 13] << 8);
		Sangle = buff[pointer + 14] + (buff[pointer + 15] << 8);
		Eangle = buff[pointer + 16] + (buff[pointer + 17] << 8);
		dx = buff[pointer + 18] + (buff[pointer + 19] << 8);
		dy = buff[pointer + 20] + (buff[pointer + 21] << 8);
		I_num = buff[pointer + 22];
		D_num = buff[pointer + 23];
		Alig = buff[pointer + 24];
		zk_id = buff[pointer + 25];
		color = buff[pointer + 26] + (buff[pointer + 27] << 8) + (buff[pointer + 28] << 16);
		S_id = buff[pointer + 29] + (buff[pointer + 30] << 8);
		E_id = buff[pointer + 31] + (buff[pointer + 32] << 8);
		flag = buff[pointer + 33];
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
		dx += Pop_up_x;
		dy += Pop_up_y;
	}

	if (fornt_id <= addr_index[11])
	{
		LT_ReadFlash(buff1, addr_index[10] + 12 * fornt_id, 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
								0, 0, pic_w, pic_add,
								pic_w, pic_h, 0);
		}
	}
    else return;    

	if (pic_w % 2)
	{
		ring_R = pic_w / 2 + 1;
		ring_CX = pic_w / 2;
		ring_CY = pic_w / 2;
	}
	else
	{
		ring_R = pic_w / 2;
		ring_CX = pic_w / 2 - 1;
		ring_CY = pic_w / 2 - 1;
	}

	if ((var[p_add * 2] << 8) + var[p_add * 2 + 1] <= Vmin)
		angle = Sangle;
	else if ((var[p_add * 2] << 8) + var[p_add * 2 + 1] >= Vmax)
		angle = Eangle;
	else
		angle = (Eangle - Sangle) * ((var[p_add * 2] << 8) + var[p_add * 2 + 1] - Vmin) / (Vmax - Vmin) + Sangle;

	if (angle >= 0 && angle <= 45)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, 0, pic_w, m_PngData, pic_w / 2, pic_h, Black);
		LT268_TFT_FillColor_Buffer2(0, 0, pic_w, m_PngData, ring_R, ring_R - 1, Black);
		for (uint16_t xx = 0; xx < ring_R; xx++)
		{
			for (uint16_t yy = ring_CY; yy < pic_h; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R - ring_R * fast_tan(angle), ring_R * 2 - 1, xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
	}
	else if (angle > 45 && angle < 90)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, 0, pic_w, m_PngData, pic_w / 2, pic_h, Black);
		LT268_TFT_FillColor_Buffer2(0, 0, pic_w, m_PngData, ring_R, ring_R - 1, Black);
		for (uint16_t xx = 0; xx < ring_R; xx++)
		{
			for (uint16_t yy = ring_CY; yy < pic_h; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, 0, ring_R + ring_R * fast_tan(90 - angle) - 1, xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
	}
	else if (angle == 90)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, 0, pic_w, m_PngData, pic_w / 2, pic_h, Black);
		LT268_TFT_FillColor_Buffer2(0, 0, pic_w, m_PngData, ring_R, ring_R - 1, Black);
	}
	else if (angle > 90 && angle <= 135)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, 0, pic_w, m_PngData, pic_w / 2, pic_h, Black);
		for (uint16_t xx = 0; xx < ring_R; xx++)
		{
			for (uint16_t yy = 0; yy < ring_R; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, 0, ring_R - ring_R * fast_tan(angle - 90), xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
	}
	else if (angle >= 135 && angle <= 180)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, 0, pic_w, m_PngData, pic_w / 2, pic_h, Black);
		for (uint16_t xx = 0; xx < ring_R; xx++)
		{
			for (uint16_t yy = 0; yy < ring_R; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R - ring_R * fast_tan(180 - angle), 0, xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
	}
	else if (angle >= 180 && angle <= 225)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, ring_CY + 1, pic_w, m_PngData, pic_w / 2, pic_h / 2, Black);
		for (uint16_t xx = ring_CX; xx < pic_w; xx++)
		{
			for (uint16_t yy = 0; yy < ring_R; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R + ring_R * fast_tan(angle - 180), 0, xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
	}
	else if (angle >= 225 && angle < 270)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, ring_CY + 1, pic_w, m_PngData, pic_w / 2, pic_h / 2, Black);
		for (uint16_t xx = ring_CX; xx < pic_w; xx++)
		{
			for (uint16_t yy = 0; yy < ring_R; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R * 2 - 1, ring_R - ring_R * fast_tan(270 - angle), xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
	}
	else if (angle == 270)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, ring_CY + 1, pic_w, m_PngData, pic_w / 2, pic_h / 2, Black);
	}
	else if (angle > 270 && angle <= 315)
	{
		for (uint16_t xx = ring_CX + 1; xx < pic_w; xx++)
		{
			for (uint16_t yy = ring_CY; yy < pic_h; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R * 2 - 1, ring_R + ring_R * fast_tan(angle - 270), xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
	}
	else if (angle >= 315 && angle < 360)
	{
		for (uint16_t xx = ring_CX + 1; xx < pic_w; xx++)
		{
			for (uint16_t yy = ring_CY; yy < pic_h; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R + ring_R * fast_tan(360 - angle), ring_R * 2 - 1, xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
	}

	if (bg_id <= addr_index[11])
	{
		LT_ReadFlash(buff1, addr_index[10] + 12 * bg_id, 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
								0, 0, pic_w, pic_add,
								pic_w, pic_h, 0xF0);
		}
	}

	if (pic_flag == 1 || pic_flag == 2)
	{
		LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
							x, y, LCD_XSIZE_TFT, FullScreen_addr,
							pic_w, pic_h, 0xF1);
	}

	if (flag == 1)
	{
		LT_ReadFlash(buff1, addr_index[2] + zk_id * 8, 4);
		zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		value = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		ll = pow(10, I_num + D_num);
		value = value % ll;
		ll = value;
		do
		{ // Get the number of digits
			n++;
			ll /= 10;
		} while (ll > 0);
		memset(Display_buff, 0, 20);
		if (D_num > 0) // With decimal point
		{
			if (D_num >= n) // All decimals
			{
				Display_buff[0] = '0';
				Display_buff[1] = '.';
				sprintf(&Display_buff[2], "%d", value);
			}
			else // Not all decimals
			{
				sprintf(Display_buff, "%d", value);
				for (i = 0; i < D_num; i++)
				{
					Display_buff[n - i] = Display_buff[n - 1 - i];
				}
				Display_buff[n - D_num] = '.';
			}
		}
		else // All integers
		{
			sprintf(Display_buff, "%d", value);
		}

		LT_ReadFlash(buff1, zk_addr, 4);

		LT_Print_zk_Font_BUFF(4, zk_addr,
							  LAY_BUFF1, LCD_XSIZE_TFT, buff1[2], buff1[3], Alig, color, Black, 0,
							  pic_w, pic_h, m_PngData, dx - x, dy - y,
							  0, 0, Display_buff, sizeof(Display_buff));
	}
	else if (flag == 2)
	{
		value = (var[p_add * 2] << 8) + var[p_add * 2 + 1];

		value = value % ((int32_t)pow(10, I_num + D_num));

		for (i = 0; i < I_num; i++) // Integer part
		{

			Display_buff[kk] = value / (int32_t)pow(10, I_num - i - 1 + D_num);

			if (Display_buff[kk] != 0 || flag1 == 1)
			{
				kk++;
				flag1 = 1; // The first place is not 0
			}
			value = value % (int32_t)pow(10, I_num - i - 1 + D_num);
		}
		if (D_num > 0)
		{
			if (flag1 == 0)
			{
				Display_buff[kk] = 0; //"."
				kk++;
			}
			Display_buff[kk] = 10; //"."
			kk++;
		}
		else
		{
			if (flag1 == 0)
			{
				Display_buff[kk] = 0; //"."
				kk++;
			}
		}
		for (i = 0; i < D_num; i++) // decimal
		{
			Display_buff[kk] = value / (int32_t)pow(10, D_num - i - 1);
			kk++;
			value = value % (int32_t)pow(10, i - 1 + D_num);
		}

		LT_ReadFlash(buff1, addr_index[10] + 12 * S_id, 12);
		PICINFO[0].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		PICINFO[0].w = buff1[4] + (buff1[5] << 8);
		PICINFO[0].h = buff1[6] + (buff1[7] << 8);
		PICINFO[0].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		PICINFO[0].flag = buff1[11];

		num_w = PICINFO[0].w;

		if (D_num > 0) // With decimal point
		{
			LT_ReadFlash(buff1, addr_index[10] + 12 * (S_id + 10), 12);

			PICINFO[1].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			PICINFO[1].w = buff1[4] + (buff1[5] << 8);
			PICINFO[1].h = buff1[6] + (buff1[7] << 8);
			PICINFO[1].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
			PICINFO[1].flag = buff1[11];
			dot_w = PICINFO[1].w;
		}

		xd = 0;
		for (i = 0; i < kk; i++)
		{
			if (Display_buff[i] >= 0 && Display_buff[i] <= 9)
			{
				LT_ReadFlash(buff1, addr_index[10] + 12 * (S_id + Display_buff[i]), 5);
				num_w = buff1[4] + (buff1[5] << 8);
				xd += num_w;
			}
			else if (Display_buff[i] == 10)
			{
				xd += dot_w;
			}
		}

		if (Alig == 0)
			dx = dx - x;
		else if (Alig == 1)
			dx = dx - x - xd / 2;
		else if (Alig == 2)
			dx = dx - x - xd + 1;

		for (i = 0; i < kk; i++)
		{
			if (Display_buff[i] >= 0 && Display_buff[i] <= 9)
			{
				LT268_pic_to_buffer(dx, dy - y, pic_w, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr + PICINFO[0].w * PICINFO[0].h * 2 * Display_buff[i],
									PICINFO[0].w, PICINFO[0].h, PICINFO[0].flag);

				LT_ReadFlash(buff1, addr_index[10] + 12 * (S_id + Display_buff[i]), 5);
				num_w = buff1[4] + (buff1[5] << 8);
				dx += num_w;
			}
			else if (Display_buff[i] == 10)
			{
				LT268_pic_to_buffer(dx, dy - y, pic_w, m_PngData,
									0, 0, PICINFO[1].w, PICINFO[1].addr,
									PICINFO[1].w, PICINFO[1].h, PICINFO[1].flag);
				dx += dot_w;
			}
		}
	}

	LT268_buffer_to_TFT(0, 0, pic_w, m_PngData,
						x, y, pic_w, pic_h);
}

uint8_t curve_num = 0;		 // Number of curve controls
uint8_t curve_flag = 0;		 // Curve timing refresh flag bit
uint8_t curve_group_sum = 1; // Total number of groups in curve area
/***********************************************************************************
 * Function Name : Real_time_curve_display_static
 * Description   : Show static curves.
 * Input         : - curve: curve info
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Real_time_curve_display_static(Curve_Info curve)
{
	uint16_t buff_w = curve.xe - curve.xs, buff_h = curve.ye - curve.ys;
	uint16_t points = 0, num = 0, yCentral = 0, x, y;

	if (R_ANGLE == 0)
	{
		x = curve.xs + curve.Width;
		points = (curve.xe - curve.xs - curve.Width * 2) / curve.Dis_HOR;
		yCentral = curve.Y_Central + curve.VD_Central * curve.MUL_Y / 256;

		// full-screen background
		LT268_pic_to_buffer(0, 0, buff_w, m_PngData,
							curve.xs, curve.ys, LCD_XSIZE_TFT, FullScreen_addr,
							buff_w, buff_h, 0);

		if (curve.dir == 0)
			num = (Curve_count[curve.channel] + 1024 - points - 1) % 1024;
		else
			num = Curve_count[curve.channel] - 1 + 1024;

		for (uint16_t i = 0; i < points; i++)
		{

			if (curve.dir == 0)
			{
				LT268_TFT_DrawLine_Width_Buffer(x - curve.xs, (yCentral - Curve_buff[curve.channel][num % 1024] * curve.MUL_Y / 256) - curve.ys,
												x + curve.Dis_HOR - curve.xs, (yCentral - Curve_buff[curve.channel][(num + 1) % 1024] * curve.MUL_Y / 256) - curve.ys,
												curve.color, curve.Width, buff_w);

				x = x + curve.Dis_HOR;
				num++;
			}
			else
			{
				LT268_TFT_DrawLine_Width_Buffer(x - curve.xs, (yCentral - Curve_buff[curve.channel][num % 1024] * curve.MUL_Y / 256) - curve.ys,
												x + curve.Dis_HOR - curve.xs, (yCentral - Curve_buff[curve.channel][(num - 1) % 1024] * curve.MUL_Y / 256) - curve.ys,
												curve.color, curve.Width, buff_w);

				x = x + curve.Dis_HOR;
				num--;
			}
		}

		// display
		LT268_buffer_to_TFT(0, 0, buff_w, m_PngData,
							curve.xs, curve.ys, buff_w, buff_h);
	}
}

/***********************************************************************************
 * Function Name : Real_time_curve_display_dynamic
 * Description   : Show Dynamic Curves.
 * Input         : - group: which group of curve
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Real_time_curve_display_dynamic(uint8_t group)
{
	uint16_t points = 0, num = 0, yCentral = 0, x, y;
	uint16_t i = 0, j = 0;
	uint8_t once_flag = 0;
	uint8_t temp = 0;
	uint16_t buff_w = 0, buff_h = 0;

	for (i = 0; i < curve_num; i++)
	{
		if (gCurve_Info[i].group == group)
		{
			// Only load the background once under the same group
			if (once_flag == 0)
			{
				temp = i;
				once_flag = 1;
				buff_w = gCurve_Info[temp].xe - gCurve_Info[temp].xs;
				buff_h = gCurve_Info[temp].ye - gCurve_Info[temp].ys;

				// full_screen background
				LT268_pic_to_buffer(0, 0, buff_w, m_PngData,
									gCurve_Info[temp].xs, gCurve_Info[temp].ys, LCD_XSIZE_TFT, FullScreen_addr,
									buff_w, buff_h, 0);
			}

			x = gCurve_Info[i].xs + gCurve_Info[i].Width;
			points = (gCurve_Info[i].xe - gCurve_Info[i].xs - gCurve_Info[i].Width * 2) / gCurve_Info[i].Dis_HOR;
			yCentral = gCurve_Info[i].Y_Central + gCurve_Info[i].VD_Central * gCurve_Info[i].MUL_Y / 256;

			if (gCurve_Info[i].dir == 0)
				num = (Curve_count[gCurve_Info[i].channel] + 1024 - points - 1) % 1024;
			else
				num = Curve_count[gCurve_Info[i].channel] - 1 + 1024;

			// draw points
			for (j = 0; j < points; j++)
			{
				if (gCurve_Info[i].dir == 0)
				{
					LT268_TFT_DrawLine_Width_Buffer(
						x - gCurve_Info[i].xs, (yCentral - Curve_buff[gCurve_Info[i].channel][num % 1024] * gCurve_Info[i].MUL_Y / 256) - gCurve_Info[i].ys,
						(x + gCurve_Info[i].Dis_HOR) - gCurve_Info[i].xs, (yCentral - Curve_buff[gCurve_Info[i].channel][(num + 1) % 1024] * gCurve_Info[i].MUL_Y / 256) - gCurve_Info[i].ys,
						gCurve_Info[i].color, gCurve_Info[i].Width, buff_w);

					x = x + gCurve_Info[i].Dis_HOR;
					num++;
				}
				else
				{
					LT268_TFT_DrawLine_Width_Buffer(
						x - gCurve_Info[i].xs, (yCentral - Curve_buff[gCurve_Info[i].channel][num % 1024] * gCurve_Info[i].MUL_Y / 256) - gCurve_Info[i].ys,
						(x + gCurve_Info[i].Dis_HOR) - gCurve_Info[i].xs, (yCentral - Curve_buff[gCurve_Info[i].channel][(num - 1) % 1024] * gCurve_Info[i].MUL_Y / 256) - gCurve_Info[i].ys,
						gCurve_Info[i].color, gCurve_Info[i].Width, buff_w);

					x = x + gCurve_Info[i].Dis_HOR;
					num--;
				}
			}
		}
	}

	// display
	LT268_buffer_to_TFT(0, 0, buff_w, m_PngData,
						gCurve_Info[temp].xs, gCurve_Info[temp].ys, buff_w, buff_h);
}

/***********************************************************************************
* Function Name	: Curve_display
* Description	: Get curves info.
* Input         : - type: curves info sources
				  - buff: curves info
* Output        : None
* Return        : None
************************************************************************************/
void Curve_display(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, p_len, pointer;
	uint16_t xs = 0, ys = 0, xe = 0, ye = 0, Y_Central = 0, VD_Central = 0, MUL_Y = 0;
	uint32_t color = 0;
	uint8_t channel = 0;
	uint8_t Dis_HOR = 0;
	uint8_t Width = 0;
	uint8_t i = 0;
	uint8_t count = 0;
	uint8_t dir = 0;

	if (type == 0) // instruction information source is configuration file
	{
		xs = buff[5] + (buff[6] << 8);
		ys = buff[7] + (buff[8] << 8);
		xe = buff[9] + (buff[10] << 8);
		ye = buff[11] + (buff[12] << 8);
		Y_Central = buff[13] + (buff[14] << 8);
		VD_Central = buff[15] + (buff[16] << 8);
		MUL_Y = buff[17] + (buff[18] << 8);
		color = buff[19] + (buff[20] << 8) + (buff[21] << 16);
		channel = buff[22] & 0x7F;
		dir = (buff[22] & 0x80) >> 7;
		Dis_HOR = buff[23];
		Width = buff[24];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		xs = buff[pointer] + (buff[pointer + 1] << 8);
		ys = buff[pointer + 2] + (buff[pointer + 3] << 8);
		xe = buff[pointer + 4] + (buff[pointer + 5] << 8);
		ye = buff[pointer + 6] + (buff[pointer + 7] << 8);
		Y_Central = buff[pointer + 8] + (buff[pointer + 9] << 8);
		VD_Central = buff[pointer + 10] + (buff[pointer + 11] << 8);
		MUL_Y = buff[pointer + 12] + (buff[pointer + 13] << 8);
		color = buff[pointer + 14] + (buff[pointer + 15] << 8) + (buff[pointer + 16] << 16);
		channel = buff[pointer + 17] & 0x7F;
		dir = (buff[pointer + 17] & 0x80) >> 7;
		Dis_HOR = buff[pointer + 18];
		Width = buff[pointer + 19];
	}
	
	if (Pop_up_flag == 1) // Popup offset
	{
		xs += Pop_up_x;
		ys += Pop_up_y;
		xe += Pop_up_x;
		ye += Pop_up_y;
	}
	
	Y_Central = Y_Central + ys; // Ys is the relative coordinate

	gCurve_Info[curve_num].xs = xs;
	gCurve_Info[curve_num].ys = ys;
	gCurve_Info[curve_num].xe = xe;
	gCurve_Info[curve_num].ye = ye;
	gCurve_Info[curve_num].Y_Central = Y_Central;
	gCurve_Info[curve_num].VD_Central = VD_Central;
	gCurve_Info[curve_num].MUL_Y = MUL_Y;
	gCurve_Info[curve_num].color = color;
	gCurve_Info[curve_num].channel = channel;
	gCurve_Info[curve_num].Dis_HOR = Dis_HOR;
	gCurve_Info[curve_num].Width = Width;
	gCurve_Info[curve_num].dir = dir;

	Real_time_curve_display_static(gCurve_Info[curve_num]);
	curve_update_flag[gCurve_Info[curve_num].channel] = 0;

	// Group curve controls
	if (curve_num)
	{
		for (i = 0; i < curve_num; i++)
		{
			// If x y w h is different, add a group of areas
			if (gCurve_Info[curve_num].xs != gCurve_Info[i].xs || gCurve_Info[curve_num].ys != gCurve_Info[i].ys || gCurve_Info[curve_num].xe != gCurve_Info[i].xe || gCurve_Info[curve_num].ye != gCurve_Info[i].ye)
			{
				count++;
			}
			else
			{
				gCurve_Info[curve_num].group = gCurve_Info[i].group;
				break;
			}
		}

		// Indicates that the latest control is compared with all previous controls. If the area is different, a new group of areas will be added
		if (count == curve_num)
		{
			curve_group_sum++;
			gCurve_Info[curve_num].group = curve_group_sum;
		}
	}
	else // The first curve control defaults to group 0
	{
		curve_group_sum = 1;
		gCurve_Info[curve_num].group = curve_group_sum;
	}

	curve_num++;
}

void Display_Curve(void)
{
	uint8_t i = 0, j = 0;
	if (curve_num && curve_flag)
	{
		curve_flag = 0;
		for (i = 1; i <= curve_group_sum; i++)
		{
			for (j = 0; j < curve_num; j++)
			{
				////When a channel data is updated, multiple controls in the same group will be updated accordingly
				if (curve_update_flag[gCurve_Info[j].channel] && gCurve_Info[j].group == i)
				{
					Real_time_curve_display_dynamic(i);
					break;
				}
			}
		}
		for (i = 0; i < 8; i++) // After all the curves are updated, clear the flag
		{
			curve_update_flag[i] = 0;
		}
	}
}


Count_Info gCount_Info[COUNT_SIZE];
Record_count_Info gRecord_count_Info[20];
uint8_t Count_sum = 0;
uint8_t Count_flag = 0;
uint8_t Record_count = 0;
uint16_t Count_reg[8];
uint8_t Count_reg_num;

/***********************************************************************************
* Function Name	: count_display
* Description	: Get time counter info.
* Input         : - type: time counter info sources
				  - buff: time counter info
* Output        : None
* Return        : None
************************************************************************************/
void count_display(uint8_t type, uint8_t *buff)
{
	uint8_t i = 0;

	if (type == 0)
	{
		gCount_Info[Count_sum].v_add = (buff[5] + (buff[6] << 8));
		gCount_Info[Count_sum].t_add = buff[7] + (buff[8] << 8);
		gCount_Info[Count_sum].c_add = buff[9] + (buff[10] << 8);
		gCount_Info[Count_sum].x = buff[11] + (buff[12] << 8);
		gCount_Info[Count_sum].y = buff[13] + (buff[14] << 8);
		gCount_Info[Count_sum].ID_start = buff[15] + (buff[16] << 8);
		gCount_Info[Count_sum].dis_mode = buff[17];
		gCount_Info[Count_sum].dir = buff[18];
		gCount_Info[Count_sum].end_mode = buff[19];
		gCount_Info[Count_sum].end_feedback = buff[20];
		gCount_Info[Count_sum].var_addr[0] = buff[21] + (buff[22] << 8);
		gCount_Info[Count_sum].var[0] = buff[23] + (buff[24] << 8);
		gCount_Info[Count_sum].var_addr[1] = buff[25] + (buff[26] << 8);
		gCount_Info[Count_sum].var[1] = buff[27] + (buff[28] << 8);
		gCount_Info[Count_sum].var_addr[2] = buff[29] + (buff[30] << 8);
		gCount_Info[Count_sum].var[2] = buff[31] + (buff[32] << 8);
		gCount_Info[Count_sum].var_addr[3] = buff[33] + (buff[34] << 8);
		gCount_Info[Count_sum].var[3] = buff[35] + (buff[36] << 8);
		gCount_Info[Count_sum].var_addr[4] = buff[37] + (buff[38] << 8);
		gCount_Info[Count_sum].var[4] = buff[39] + (buff[40] << 8);
		gCount_Info[Count_sum].var_addr[5] = buff[41] + (buff[42] << 8);
		gCount_Info[Count_sum].var[5] = buff[43] + (buff[44] << 8);
		gCount_Info[Count_sum].var_addr[6] = buff[45] + (buff[46] << 8);
		gCount_Info[Count_sum].var[6] = buff[47] + (buff[48] << 8);
		gCount_Info[Count_sum].var_addr[7] = buff[49] + (buff[50] << 8);
		gCount_Info[Count_sum].var[7] = buff[51] + (buff[52] << 8);
		
		for(uint8_t i=0;i<8;i++)
			Var_AddrRemapping(&gCount_Info[Count_sum].var_addr[i]);
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		gCount_Info[Count_sum].x += Pop_up_x;
		gCount_Info[Count_sum].y += Pop_up_y;
	}

	for (i = 0; i < Record_count; i++)
	{
		if (gCount_Info[Count_sum].v_add == gRecord_count_Info[i].v_add)
		{
			gRecord_count_Info[i].v_add = gRecord_count_Info[Record_count - 1].v_add;
			gRecord_count_Info[i].t_add = gRecord_count_Info[Record_count - 1].t_add;
			gRecord_count_Info[i].c_add = gRecord_count_Info[Record_count - 1].c_add;
			gRecord_count_Info[i].dir = gRecord_count_Info[Record_count - 1].dir;
			gRecord_count_Info[i].end_feedback = gRecord_count_Info[Record_count - 1].end_feedback;
			gRecord_count_Info[i].var[0] = gRecord_count_Info[Record_count - 1].var[0];
			gRecord_count_Info[i].var_addr[0] = gRecord_count_Info[Record_count - 1].var_addr[0];
			gRecord_count_Info[i].var[1] = gRecord_count_Info[Record_count - 1].var[1];
			gRecord_count_Info[i].var_addr[1] = gRecord_count_Info[Record_count - 1].var_addr[1];
			gRecord_count_Info[i].var[2] = gRecord_count_Info[Record_count - 1].var[2];
			gRecord_count_Info[i].var_addr[2] = gRecord_count_Info[Record_count - 1].var_addr[2];
			gRecord_count_Info[i].var[3] = gRecord_count_Info[Record_count - 1].var[3];
			gRecord_count_Info[i].var_addr[3] = gRecord_count_Info[Record_count - 1].var_addr[3];
			gRecord_count_Info[i].var[4] = gRecord_count_Info[Record_count - 1].var[4];
			gRecord_count_Info[i].var_addr[4] = gRecord_count_Info[Record_count - 1].var_addr[4];
			gRecord_count_Info[i].var[5] = gRecord_count_Info[Record_count - 1].var[5];
			gRecord_count_Info[i].var_addr[5] = gRecord_count_Info[Record_count - 1].var_addr[5];
			gRecord_count_Info[i].var[6] = gRecord_count_Info[Record_count - 1].var[6];
			gRecord_count_Info[i].var_addr[6] = gRecord_count_Info[Record_count - 1].var_addr[6];
			gRecord_count_Info[i].var[7] = gRecord_count_Info[Record_count - 1].var[7];
			gRecord_count_Info[i].var_addr[7] = gRecord_count_Info[Record_count - 1].var_addr[7];
			Record_count--;
		}
	}
	gCount_Info[Count_sum].last_w = 0;
	Display_Count(Count_sum);

	Count_sum++;
}
uint8_t Display_Count(uint8_t i)
{
	uint16_t ID[11];
	uint8_t buff[12] = {0};
	uint16_t temp;
	uint16_t x_time = 0;
	uint8_t j = 0, k = 0;

	if (((var[gCount_Info[i].c_add * 2] << 8) + var[gCount_Info[i].c_add * 2 + 1]) == 2)
	{
		if (gCount_Info[i].last_w > 0)
		{
			LT_ReadFlash(buff, addr_index[10] + 12 * (gCount_Info[i].ID_start), 12);
			pic_h = buff[6] + (buff[7] << 8);
			gCount_Info[i].last_w = 0;
		}
		return 0;
	}
	if (gCount_Info[i].dis_mode == 0)
	{
		return 0;
	}
	else if (gCount_Info[i].dis_mode == 1) // Hour, minute and second
	{
		temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
		ID[0] = temp / 36000 % 10;
		ID[1] = temp / 3600 % 10;
		ID[2] = 10;
		temp = temp % 3600;
		ID[3] = temp / 600 % 10;
		ID[4] = temp / 60 % 10;
		ID[5] = 10;
		temp = temp % 60;
		ID[6] = temp / 10 % 10;
		ID[7] = temp % 10;
		k = 7;
	}
	else if (gCount_Info[i].dis_mode == 2)
	{
		temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];

		ID[0] = temp / 36000 % 10;
		ID[1] = temp / 3600 % 10;
		ID[2] = 10;
		temp = temp % 3600;
		ID[3] = temp / 600 % 10;
		ID[4] = temp / 60 % 10;
		k = 4;
	}
	else if (gCount_Info[i].dis_mode == 3)
	{
		temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
//		temp = temp % 3600;
//		ID[0] = temp / 600 % 10;
//		ID[1] = temp / 60 % 10;
//		ID[2] = 10;
//		temp = temp % 60;
//		ID[3] = temp / 10 % 10;
//		ID[4] = temp % 10;

		temp = temp % 60000;
		ID[0] = temp / 10000 % 10;
		ID[1] = temp / 1000 % 10;
		ID[2] = 10;
		temp = temp % 1000;
		ID[3] = temp / 100 % 10;
		ID[4] = temp % 100/10;
		
		k = 4;
	}
	else if (gCount_Info[i].dis_mode == 4)
	{

		if (((var[gCount_Info[i].v_add * 2] << 8) + var[gCount_Info[i].v_add * 2 + 1]) > 10000)
		{
			temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
			ID[0] = temp / 10000 % 10;
			ID[1] = temp / 1000 % 10;
			ID[2] = temp / 100 % 10;
			ID[3] = temp / 10 % 10;
			ID[4] = temp % 10;
			k = 4;
		}
		else if (((var[gCount_Info[i].v_add * 2] << 8) + var[gCount_Info[i].v_add * 2 + 1]) > 1000)
		{
			temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
			ID[0] = temp / 1000 % 10;
			ID[1] = temp / 100 % 10;
			ID[2] = temp / 10 % 10;
			ID[3] = temp % 10;
			k = 3;
		}
		else if (((var[gCount_Info[i].v_add * 2] << 8) + var[gCount_Info[i].v_add * 2 + 1]) > 100)
		{
			temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
			ID[0] = temp / 100 % 10;
			ID[1] = temp / 10 % 10;
			ID[2] = temp % 10;
			k = 2;
		}
		else if (((var[gCount_Info[i].v_add * 2] << 8) + var[gCount_Info[i].v_add * 2 + 1]) > 10)
		{
			temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
			ID[0] = temp / 10 % 10;
			ID[1] = temp % 10;
			k = 1;
		}
		else
		{
			temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
			ID[0] = temp % 10;
			k = 0;
		}
	}
	var_temp[gCount_Info[i].t_add * 2] = var[gCount_Info[i].t_add * 2];
	var_temp[gCount_Info[i].t_add * 2 + 1] = var[gCount_Info[i].t_add * 2 + 1];

	/*In the keyboard input interface*/
	if (DioKb_flag == 1)
	{
		if (!(gCount_Info[i].x > gDio_Info[Dio_num].Xe || (gCount_Info[i].x + x_time) < gDio_Info[Dio_num].Xs || gCount_Info[i].y > gDio_Info[Dio_num].Ye || (gCount_Info[i].y + pic_h) < gDio_Info[Dio_num].Ys))
		{
			return 0;
		}
	}
	else if (AioKb_flag == 1)
	{
		if (!(gCount_Info[i].x > gAio_Info[Aio_num].Xe || (gCount_Info[i].x + x_time) < gAio_Info[Aio_num].Xs || gCount_Info[i].y > gAio_Info[Aio_num].Ye || (gCount_Info[i].y + pic_h) < gAio_Info[Aio_num].Ys))
		{
			return 0;
		}
	}
	else if (GBKioKb_flag == 1)
	{
		if (!(gCount_Info[i].x > gGBKio_Info[GBKio_num].Xe || (gCount_Info[i].x + x_time) < gGBKio_Info[GBKio_num].Xs || gCount_Info[i].y > gGBKio_Info[GBKio_num].Ye || (gCount_Info[i].y + pic_h) < gGBKio_Info[GBKio_num].Ys))
		{
			return 0;
		}
	}

	for (j = 0; j <= k; j++)
	{
		if (gCount_Info[i].ID_start + ID[j] >= addr_index[11])
			continue; // picture is available
		LT_ReadFlash(buff, addr_index[10] + 12 * (gCount_Info[i].ID_start + ID[j]), 12);

		pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		pic_w = buff[4] + (buff[5] << 8);
		pic_h = buff[6] + (buff[7] << 8);
		pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		pic_flag = buff[11];

		if (!page_buff_flag)
		{
			if (pic_len != 0 && pic_flag != 0xFF) // picture is not empty
			{
				if (GIF_count_flag == 1)
				{
					LT268_pic_to_buffer(gCount_Info[i].x + x_time, gCount_Info[i].y, LCD_XSIZE_TFT, m_PngData,
										0, 0, pic_w, pic_add,
										pic_w, pic_h, 2);
				}
				else
				{
					if (pic_flag == 0)
						LT268_TFT_ShowPicture(gCount_Info[i].x + x_time, gCount_Info[i].y, pic_w, pic_h, pic_add);
					else if (pic_flag == 1)
						LT268_TFT_ShowPicture_Png(gCount_Info[i].x + x_time, gCount_Info[i].y, pic_w, pic_h, pic_add);
					else if (pic_flag == 2)
					{
						LT268_pic_to_buffer(gCount_Info[i].x + x_time, gCount_Info[i].y, LCD_XSIZE_TFT, m_PngData,
											gCount_Info[i].x + x_time, gCount_Info[i].y, LCD_XSIZE_TFT, FullScreen_addr,
											pic_w, pic_h, 0);
						LT268_pic_to_buffer(gCount_Info[i].x + x_time, gCount_Info[i].y, LCD_XSIZE_TFT, m_PngData,
											0, 0, pic_w, pic_add,
											pic_w, pic_h, 2);
						LT268_buffer_to_TFT(gCount_Info[i].x + x_time, gCount_Info[i].y, LCD_XSIZE_TFT, m_PngData,
											gCount_Info[i].x + x_time, gCount_Info[i].y, pic_w, pic_h);
						//					LT268_TFT_ShowPicture_Png_Pixel(gCount_Info[i].x + x_time, gCount_Info[i].y, pic_w, pic_h, pic_add);	printf("qqq \r\n");
					}
				}
				x_time += pic_w;
			}
		}
		else
		{
			if (pic_len != 0 && pic_flag != 0xFF) // picture is not empty
			{
				if (GIF_count_flag == 1)
				{
					LT268_pic_to_buffer(gCount_Info[i].x + x_time, gCount_Info[i].y, LCD_XSIZE_TFT, m_PngData,
										0, 0, pic_w, pic_add,
										pic_w, pic_h, 2);
				}
				else
				{
					LT268_pic_to_buffer(gCount_Info[i].x + x_time, gCount_Info[i].y, LCD_XSIZE_TFT, m_PngData,
										0, 0, pic_w, pic_add,
										pic_w, pic_h, pic_flag);
					//					LT268_TFT_ShowPicture_Png_Pixel(gCount_Info[i].x + x_time, gCount_Info[i].y, pic_w, pic_h, pic_add);	printf("qqq \r\n");
				}
				x_time += pic_w;
			}
		}

	}

	gCount_Info[i].last_w = x_time;
}

void show_Count(void)
{
	if (Count_sum > 0 && Count_flag == 1)
	{
		Count_flag = 0;
		for (uint8_t i = 0; i < Count_sum; i++)
		{
			if (((var[gCount_Info[i].c_add * 2] << 8) + var[gCount_Info[i].c_add * 2 + 1]) != 0)
				Display_Count(i);
			//else if (((var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1]) !=
			//		 (var_temp[gCount_Info[i].t_add * 2] << 8) + var_temp[gCount_Info[i].t_add * 2 + 1])
			//	Display_Count(i);
		}
	}
}

void Saving_counting_parameters(void)
{
	uint8_t i, j;
	for (i = 0; i < Count_sum; i++)
	{

		if (Record_count > 0 && gCount_Info[i].end_mode == 1)
		{
			for (j = 0; j < Record_count; j++)
			{
				if (gCount_Info[i].v_add == gRecord_count_Info[j].v_add)
				{
					break;
				}
				if (j == Record_count - 1)
				{
					gRecord_count_Info[Record_count].v_add = gCount_Info[i].v_add;
					gRecord_count_Info[Record_count].t_add = gCount_Info[i].t_add;
					gRecord_count_Info[Record_count].c_add = gCount_Info[i].c_add;
					gRecord_count_Info[Record_count].dir = gCount_Info[i].dir;
					gRecord_count_Info[Record_count].end_feedback = gCount_Info[i].end_feedback;
					gRecord_count_Info[Record_count].var[0] = gCount_Info[i].var[0];
					gRecord_count_Info[Record_count].var_addr[0] = gCount_Info[i].var_addr[0];
					gRecord_count_Info[Record_count].var[1] = gCount_Info[i].var[1];
					gRecord_count_Info[Record_count].var_addr[1] = gCount_Info[i].var_addr[1];
					gRecord_count_Info[Record_count].var[2] = gCount_Info[i].var[2];
					gRecord_count_Info[Record_count].var_addr[2] = gCount_Info[i].var_addr[2];
					gRecord_count_Info[Record_count].var[3] = gCount_Info[i].var[3];
					gRecord_count_Info[Record_count].var_addr[3] = gCount_Info[i].var_addr[3];
					gRecord_count_Info[Record_count].var[4] = gCount_Info[i].var[4];
					gRecord_count_Info[Record_count].var_addr[4] = gCount_Info[i].var_addr[4];
					gRecord_count_Info[Record_count].var[5] = gCount_Info[i].var[5];
					gRecord_count_Info[Record_count].var_addr[5] = gCount_Info[i].var_addr[5];
					gRecord_count_Info[Record_count].var[6] = gCount_Info[i].var[6];
					gRecord_count_Info[Record_count].var_addr[6] = gCount_Info[i].var_addr[6];
					gRecord_count_Info[Record_count].var[7] = gCount_Info[i].var[7];
					gRecord_count_Info[Record_count].var_addr[7] = gCount_Info[i].var_addr[7];
					Record_count++;
				}
			}
		}
		else if (gCount_Info[i].end_mode == 1)
		{
			gRecord_count_Info[Record_count].v_add = gCount_Info[i].v_add;
			gRecord_count_Info[Record_count].t_add = gCount_Info[i].t_add;
			gRecord_count_Info[Record_count].c_add = gCount_Info[i].c_add;
			gRecord_count_Info[Record_count].dir = gCount_Info[i].dir;
			gRecord_count_Info[Record_count].end_feedback = gCount_Info[i].end_feedback;
			gRecord_count_Info[Record_count].var[0] = gCount_Info[i].var[0];
			gRecord_count_Info[Record_count].var_addr[0] = gCount_Info[i].var_addr[0];
			gRecord_count_Info[Record_count].var[1] = gCount_Info[i].var[1];
			gRecord_count_Info[Record_count].var_addr[1] = gCount_Info[i].var_addr[1];
			gRecord_count_Info[Record_count].var[2] = gCount_Info[i].var[2];
			gRecord_count_Info[Record_count].var_addr[2] = gCount_Info[i].var_addr[2];
			gRecord_count_Info[Record_count].var[3] = gCount_Info[i].var[3];
			gRecord_count_Info[Record_count].var_addr[3] = gCount_Info[i].var_addr[3];
			gRecord_count_Info[Record_count].var[4] = gCount_Info[i].var[4];
			gRecord_count_Info[Record_count].var_addr[4] = gCount_Info[i].var_addr[4];
			gRecord_count_Info[Record_count].var[5] = gCount_Info[i].var[5];
			gRecord_count_Info[Record_count].var_addr[5] = gCount_Info[i].var_addr[5];
			gRecord_count_Info[Record_count].var[6] = gCount_Info[i].var[6];
			gRecord_count_Info[Record_count].var_addr[6] = gCount_Info[i].var_addr[6];
			gRecord_count_Info[Record_count].var[7] = gCount_Info[i].var[7];
			gRecord_count_Info[Record_count].var_addr[7] = gCount_Info[i].var_addr[7];
			Record_count++;
		}
	}
}

/***********************************************************************************
 * Function Name : pop_up_touch
 * Description   : Touch detection of pop-up window.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void pop_up_touch(void)
{
	uint8_t i = 0;
	uint8_t rebuf[20];
	uint16_t w, h;

	// press down
	if (gTpInfo.sta)
	{

		for (i = 0; i < Pop_up_count; i++)
		{
			if (gTpInfo.x[0] >= gPop_up_Info[i].Xs && gTpInfo.y[0] >= gPop_up_Info[i].Ys && gTpInfo.x[0] <= gPop_up_Info[i].Xe && gTpInfo.y[0] <= gPop_up_Info[i].Ye && Pop_up_press == 0 && button_Press_flag == 0)
			{
				if (gPop_up_Info[i].press_id != 0xFFFF)
				{
					Display_Icon(gPop_up_Info[i].press_id, gPop_up_Info[i].Xs, gPop_up_Info[i].Ys, 0);
				}

				if (Pop_up_flag == 0)
				{
					if ((gPop_up_Info[i].function & 0x01) == 1)
					{
					}
					else
					{
					}
				}
				Pop_up_num = i;
				button_Press_flag = 1;
				Pop_up_press = 1;
				// Pop_up_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}

	if (Button_Key_Code_Flag == 1)
	{
		for (i = 0; i < Pop_up_count; i++)
		{
			if (gPop_up_Info[i].Xs == 0xFFFF && Button_Key_Code == gPop_up_Info[i].Ys)
			{

				Button_Key_Code_Flag = 0;
				Button_Key_Code = 0;
				if (Pop_up_flag == 0)
				{
					// reserve
					if ((gPop_up_Info[i].function & 0x01) == 1)
					{
					}
					else
					{
					}
				}
				Pop_up_num = i;
				button_Press_flag = 1;
				Pop_up_press = 1;
				// Pop_up_flag = 1;
			}
			if (i == (Pop_up_count - 1))
				Button_Key_Code_Flag = 0; // Clear the flag bit after no key code is triggered
		}
	}

	if (gTpInfo.sta == 0 && Pop_up_press == 1)
	{
		if (gPop_up_Info[Pop_up_num].Code == 0xC008)
		{
			rebuf[3] = 0x41;
			rebuf[4] = 0xFF;
			rebuf[5] = 0xFF;
			rebuf[6] = gPop_up_Info[Pop_up_num].Keyvalue >> 8;
			rebuf[7] = gPop_up_Info[Pop_up_num].Keyvalue & 0xFF;
			LT_SendData_CRC_Frame(rebuf, 5);
		}

		Pop_up_flag = 0;
		if (gPop_up_Info[Pop_up_num].id != 0xFFFF)
		{
			Display_Icon(gPop_up_Info[Pop_up_num].id, gPop_up_Info[Pop_up_num].Xs, gPop_up_Info[Pop_up_num].Ys, 0);
		}
		Pop_up_flag = 1;

		if (gPop_up_Info[Pop_up_num].function & 0x02)
		{
		}

		Pop_up_x = gPop_up_Info[Pop_up_num].pop_up_x;
		Pop_up_y = gPop_up_Info[Pop_up_num].pop_up_y;
		Pop_up_id = gPop_up_Info[Pop_up_num].pop_up_id;

//		 printf("Pop_up_num=%d \r\n",Pop_up_num);
//		 printf("Pop_up_xy= %d  %d  id  %d  \r\n",Pop_up_x,Pop_up_y,Pop_up_id);
		if (gPop_up_Info[Pop_up_num].pop_up_id != 0xFFFF)
		{
			Display_pop_up(gPop_up_Info[Pop_up_num].pop_up_id, gPop_up_Info[Pop_up_num].pop_up_x, gPop_up_Info[Pop_up_num].pop_up_y);
		}

		Pop_up_press = 0;
		button_Press_flag = 0;
	}
}

/***********************************************************************************
 * Function Name : Basic_touch
 * Description   : Touch detection of Basic_touch.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Basic_touch(void)
{
	uint8_t i = 0;
	uint8_t rebuf[20];

	// press down
	if (gTpInfo.sta)
	{
		for (i = 0; i < Basci_count; i++)
		{

			if (gTpInfo.x[0] >= gBasci_Info[i].Xs && gTpInfo.y[0] >= gBasci_Info[i].Ys && gTpInfo.x[0] <= gBasci_Info[i].Xe && gTpInfo.y[0] <= gBasci_Info[i].Ye && Basci_flag == 0 && button_Press_flag == 0)
			{
				if (gBasci_Info[i].press_id != 0xFFFF)
				{
					Display_Icon(gBasci_Info[i].press_id, gBasci_Info[i].Xs, gBasci_Info[i].Ys, 0);
				}
				Basci_num = i;
				Basci_flag = 1;
				button_Press_flag = 1;
				if (buzzer)
					touch_buzzer();
				if(gBasci_Info[Basci_num].Keyvalue==0x600)
				{
					touch_nolock_flag=1;touch_nolock_time=0;
					//printf("dddddddd888\n");
				}		
				if(gBasci_Info[Basci_num].Keyvalue==0x0C00)	
				{
                  Double_finger_flag=1;
				  //printf("18181818818\n");
				}	
			}
		}
	}

	// raise
	if (gTpInfo.sta == 0 && Basci_flag == 1)
	{
		if(gBasci_Info[Basci_num].Keyvalue==0x600)	touch_nolock_flag=0;
		if (gBasci_Info[Basci_num].Code == 0xC001)
		{
			rebuf[3] = 0x41;
			rebuf[4] = 0xFF;
			rebuf[5] = 0xFF;
			rebuf[6] = gBasci_Info[Basci_num].Keyvalue >> 8;
			rebuf[7] = gBasci_Info[Basci_num].Keyvalue & 0xFF;
			LT_SendData_CRC_Frame(rebuf, 5);
		}
		if (gBasci_Info[Basci_num].id != 0xFFFF)
		{
			Display_Icon(gBasci_Info[Basci_num].id, gBasci_Info[Basci_num].Xs, gBasci_Info[Basci_num].Ys, 0);
		}
		Basci_flag = 0;
		button_Press_flag = 0;
		if (gBasci_Info[Basci_num].Next_id != 0xFFFF)
		{
			Display_page(gBasci_Info[Basci_num].Next_id);
		}
		if(gBasci_Info[Basci_num].Keyvalue==0x0C00)
		   Double_finger_flag=0;
		   //printf("2929292922929\n");
	}
}

/***********************************************************************************
 * Function Name : Adj_touch
 * Description   : Touch detection of variable adjustment.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Adj_touch(void)
{
	uint8_t i = 0;
	uint8_t rebuf[20];
	int16_t sum1 = 0;
	int8_t sum0 = 0;
	int32_t sum = 0;
	uint8_t num = 0;
	uint8_t EbuffH[1],EbuffL[1];
	int16_t value = 0;
	// press down
	if (gTpInfo.sta)
	{
		for (i = 0; i < Adj_count; i++)
		{
			if (gTpInfo.x[0] >= gAdj_Info[i].Xs && gTpInfo.y[0] >= gAdj_Info[i].Ys && gTpInfo.x[0] <= gAdj_Info[i].Xe && gTpInfo.y[0] <= gAdj_Info[i].Ye && Adj_flag == 0 && button_Press_flag == 0)
			{
				if((IO_READ8(Touch_sAddr)==0&&(pic_id==33||pic_id==28||pic_id==30||pic_id==32||pic_id==33))
					||(var[0x1048*2+1]==0&&var[0x1049*2+1]==1&&i==0&&(pic_id==14))//激活模式要保留1个
					||(var[0x1048*2+1]==1&&var[0x1049*2+1]==0&&i==1&&(pic_id==14))//激活模式要保留1个
					||(((var[0x1025*2+1]==1&&var[0x1026*2+1]==1&&var[0x1027*2+1]==1&&var[0x1028*2+1]==0&&i==0)||//锁定剂量只能选3个
						(var[0x1025*2+1]==1&&var[0x1026*2+1]==1&&var[0x1027*2+1]==0&&var[0x1028*2+1]==1&&i==1)||
						(var[0x1025*2+1]==1&&var[0x1026*2+1]==0&&var[0x1027*2+1]==1&&var[0x1028*2+1]==1&&i==2)||
						(var[0x1025*2+1]==0&&var[0x1026*2+1]==1&&var[0x1027*2+1]==1&&var[0x1028*2+1]==1&&i==3))&&(pic_id==18))
					)
				{
					//printf("pic_id = %d , i = %d ,0x1025 = %d ,0x1026 = %d,0x1027 = %d,0x1028 = %d \r\n",pic_id,i,var[0x1025*2+1],var[0x1026*2+1],var[0x1027*2+1],var[0x1028*2+1]);
				}
				else
				{
					if (gAdj_Info[i].press_id != 0xFFFF)
					{
						Display_Icon(gAdj_Info[i].press_id, gAdj_Info[i].Xs, gAdj_Info[i].Ys, 0);
					}
					
					if(Count_value_show_flag)
					{
						Count_value_show_flag = FALSE;
						Count_value_show_delay = 0;
						Count_value_to_Zero();
					}
					
					if(pic_id==33)
					{
						var[0x0232 * 2 + 1] = 1;
	//					if(Touch_flag == 1)
	//					{
	//						TouchON_flag = 1;
	//						printf("adj--PWM_WriteGpioData(PWM_PORT0, 1);\r\n");
	//						PWM_WriteGpioData(PWM_PORT0, 1);
	//					}
					}
					
					Adj_num = i;
					Adj_flag = 1;
					button_Press_flag = 1;
					if (gAdj_Info[i].key_mode == 1)
					{
						Adj_loop = 1;
					}
					if (buzzer)
						touch_buzzer();
				}
			}
		}
	}

	// keep pressing
	if (Adj_loop == 1 && Adj_time > 10 && gTpInfo.sta == 1&&Double_finger_flag==0&&Long_press_lock==0)
	{
		Adj_time = 0;
		if (gAdj_Info[Adj_num].p_tpye == 0x00)
			sum = var[gAdj_Info[Adj_num].p_add * 2 + 1];
		else if (gAdj_Info[Adj_num].p_tpye == 0x80)
		{
			sum0 = var[gAdj_Info[Adj_num].p_add * 2 + 1];
			sum = sum0;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x01)
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];
		else if (gAdj_Info[Adj_num].p_tpye == 0x81)
		{
			sum1 = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];
			sum = sum1;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x02)
		{
			if (var[gAdj_Info[Adj_num].p_add * 2] >= 0x80)
				var[gAdj_Info[Adj_num].p_add * 2] = 0x40;
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 24) + (var[gAdj_Info[Adj_num].p_add * 2 + 1] << 16) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 3];
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x82)
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 24) + (var[gAdj_Info[Adj_num].p_add * 2 + 1] << 16) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 3];
		else if (gAdj_Info[Adj_num].p_tpye == 0x83)
		{
			sum = (var[gAdj_Info[Adj_num].p_add * 2 + 6] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 7];
			if (var[gAdj_Info[Adj_num].p_add * 2] >= 0x80)
				sum = sum + (0x80 << 24);
		}
		else if (gAdj_Info[Adj_num].p_tpye >= 0x40 && gAdj_Info[Adj_num].p_tpye <= 0x4F)
		{
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];
		}

		if (gAdj_Info[Adj_num].Adj_mode == 1) //+
		{
			if (gAdj_Info[Adj_num].p_tpye & 0x40)
			{
				num = gAdj_Info[Adj_num].p_tpye & 0x0F;
				if (sum & (1 << num))
					sum &= ~(1 << num);
				else
					sum |= (1 << num);
			}
			else
			{
				sum += gAdj_Info[Adj_num].Adj_step;
				if (sum > gAdj_Info[Adj_num].V_max)
				{
					if (gAdj_Info[Adj_num].Return_Mode == 0)
						sum = gAdj_Info[Adj_num].V_max;
					else
						sum = gAdj_Info[Adj_num].V_min;
				}
				else if (sum < gAdj_Info[Adj_num].V_min)
					sum = gAdj_Info[Adj_num].V_min;
			}
		}
		else // -
		{
			if (gAdj_Info[Adj_num].p_tpye & 0x40)
			{
				num = gAdj_Info[Adj_num].p_tpye & 0x0F;
				if (sum & (1 << num))
					sum &= ~(1 << num);
				else
					sum |= (1 << num);
			}
			else
			{
				sum -= gAdj_Info[Adj_num].Adj_step;

				if (sum < gAdj_Info[Adj_num].V_min)
				{
					if (gAdj_Info[Adj_num].Return_Mode == 0)
						sum = gAdj_Info[Adj_num].V_min;
					else
						sum = gAdj_Info[Adj_num].V_max;
				}
				else if (sum > gAdj_Info[Adj_num].V_max)
					sum = gAdj_Info[Adj_num].V_max;
			}
		}

		if (gAdj_Info[Adj_num].p_tpye == 0x00 || gAdj_Info[Adj_num].p_tpye == 0x80)
		{
			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum; // & 0xFF;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x01 || gAdj_Info[Adj_num].p_tpye == 0x81)
		{
			var[gAdj_Info[Adj_num].p_add * 2] = sum >> 8 & 0xFF;
			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum & 0xFF;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x02 || gAdj_Info[Adj_num].p_tpye == 0x82)
		{
			if (sum < 0)
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = sum & 0xFF;
			}
			else
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = sum & 0xFF;
			}
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x83)
		{
			if (sum < 0)
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 4] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 5] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 7] = sum & 0xFF;
			}
			else
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 4] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 5] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 7] = sum & 0xFF;
			}
		}
		else if (gAdj_Info[Adj_num].p_tpye >= 0x40 && gAdj_Info[Adj_num].p_tpye <= 0x4F)
		{
			var[gAdj_Info[Adj_num].p_add * 2] = sum >> 8 & 0xFF;
			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum & 0xFF;
		}

		if (gAdj_Info[Adj_num].p_add >= VAR_ADDR_S)
		{
			reg_operation(gAdj_Info[Adj_num].p_add);
		}
		page_date_update(pic_id);
		
		if(pic_id==27)	Mode_I_Sum = sum;
		else if(pic_id==29)	Mode_II_Sum = sum;
		else if(pic_id==31)	Mode_III_Sum = sum;	
		
	}

	// raise
	if (gTpInfo.sta == 0 && Adj_flag == 1)
	{		
		//if(pic_id==27)
		//{
		//	printf("Adj_num--%d\n",Adj_num);
		//	printf("ddddddddddddddd\n");
		//}
		
		if (gAdj_Info[Adj_num].p_tpye == 0x00)
			sum = var[gAdj_Info[Adj_num].p_add * 2 + 1];
		else if (gAdj_Info[Adj_num].p_tpye == 0x80)
		{
			sum0 = var[gAdj_Info[Adj_num].p_add * 2 + 1];
			sum = sum0;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x01)
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];
		else if (gAdj_Info[Adj_num].p_tpye == 0x81)
		{
			sum1 = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];
			sum = sum1;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x02)
		{
			if (var[gAdj_Info[Adj_num].p_add * 2] >= 0x80)
				var[gAdj_Info[Adj_num].p_add * 2] = 0x40;
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 24) + (var[gAdj_Info[Adj_num].p_add * 2 + 1] << 16) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 3];
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x82)
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 24) + (var[gAdj_Info[Adj_num].p_add * 2 + 1] << 16) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 3];
		else if (gAdj_Info[Adj_num].p_tpye == 0x83)
		{
			sum = (var[gAdj_Info[Adj_num].p_add * 2 + 6] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 7];
			if (var[gAdj_Info[Adj_num].p_add * 2] >= 0x80)
				sum = sum + (0x80 << 24);
		}
		else if (gAdj_Info[Adj_num].p_tpye >= 0x40 && gAdj_Info[Adj_num].p_tpye <= 0x4F)
		{
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];
		}

		if (gAdj_Info[Adj_num].Adj_mode == 1) //+
		{
			if (gAdj_Info[Adj_num].p_tpye & 0x40)
			{
				num = gAdj_Info[Adj_num].p_tpye & 0x0F;
				if (sum & (1 << num))
					sum &= ~(1 << num);
				else
					sum |= (1 << num);
			}
			else
			{
				if((pic_id==27||pic_id==29||pic_id==31)&&Long_press_lock==1)
				{
				}
				else	
				sum += gAdj_Info[Adj_num].Adj_step;
				if (sum > gAdj_Info[Adj_num].V_max)
				{
					if (gAdj_Info[Adj_num].Return_Mode == 0)
						sum = gAdj_Info[Adj_num].V_max;
					else
						sum = gAdj_Info[Adj_num].V_min;
				}
				else if (sum < gAdj_Info[Adj_num].V_min)
					sum = gAdj_Info[Adj_num].V_min;
			}
		}
		else // -
		{
			if (gAdj_Info[Adj_num].p_tpye & 0x40)
			{
				num = gAdj_Info[Adj_num].p_tpye & 0x0F;
				if (sum & (1 << num))
					sum &= ~(1 << num);
				else
					sum |= (1 << num);
			}
			else
			{		
				if((pic_id==27||pic_id==29||pic_id==31)&&Long_press_lock==1)
				{
				}
				else	
					sum -= gAdj_Info[Adj_num].Adj_step;
				if (sum < gAdj_Info[Adj_num].V_min)
				{
					if (gAdj_Info[Adj_num].Return_Mode == 0)
						sum = gAdj_Info[Adj_num].V_min;
					else
						sum = gAdj_Info[Adj_num].V_max;
				}
				else if (sum > gAdj_Info[Adj_num].V_max)
					sum = gAdj_Info[Adj_num].V_max;
			}
		}

		if (gAdj_Info[Adj_num].p_tpye == 0x00 || gAdj_Info[Adj_num].p_tpye == 0x80)
		{

			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum & 0xFF;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x01 || gAdj_Info[Adj_num].p_tpye == 0x81)
		{
			var[gAdj_Info[Adj_num].p_add * 2] = sum >> 8 & 0xFF;
			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum & 0xFF;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x02 || gAdj_Info[Adj_num].p_tpye == 0x82)
		{

			if (sum < 0)
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = sum & 0xFF;
			}
			else
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = sum & 0xFF;
			}
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x83)
		{
			if (sum < 0)
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 4] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 5] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 7] = sum & 0xFF;
			}
			else
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 4] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 5] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 7] = sum & 0xFF;
			}
		}
		else if (gAdj_Info[Adj_num].p_tpye >= 0x40 && gAdj_Info[Adj_num].p_tpye <= 0x4F)
		{
			var[gAdj_Info[Adj_num].p_add * 2] = sum >> 8 & 0xFF;
			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum & 0xFF;
		}

		if (gAdj_Info[Adj_num].Code == 0xC003) // serial port return
		{
			rebuf[3] = 0x41;
			if (gAdj_Info[Adj_num].p_tpye == 0x00 || gAdj_Info[Adj_num].p_tpye == 0x80 || gAdj_Info[Adj_num].p_tpye == 0x01 ||
				gAdj_Info[Adj_num].p_tpye == 0x81 || (gAdj_Info[Adj_num].p_tpye >= 0x40 && gAdj_Info[Adj_num].p_tpye <= 0x4F))
			{
				rebuf[4] = gAdj_Info[Adj_num].p_add >> 8;
				rebuf[5] = gAdj_Info[Adj_num].p_add & 0xFF;
				rebuf[6] = var[gAdj_Info[Adj_num].p_add * 2];
				rebuf[7] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
				LT_SendData_CRC_Frame(rebuf, 5);
			}
			else if (gAdj_Info[Adj_num].p_tpye == 0x02 || gAdj_Info[Adj_num].p_tpye == 0x82)
			{
				rebuf[4] = gAdj_Info[Adj_num].p_add >> 8;
				rebuf[5] = gAdj_Info[Adj_num].p_add & 0xFF;
				rebuf[6] = var[gAdj_Info[Adj_num].p_add * 2];
				rebuf[7] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
				rebuf[8] = var[gAdj_Info[Adj_num].p_add * 2 + 2];
				rebuf[9] = var[gAdj_Info[Adj_num].p_add * 2 + 3];
				LT_SendData_CRC_Frame(rebuf, 7);
			}
			else if (gAdj_Info[Adj_num].p_tpye == 0x03 || gAdj_Info[Adj_num].p_tpye == 0x83)
			{
				rebuf[4] = gAdj_Info[Adj_num].p_add >> 8;
				rebuf[5] = gAdj_Info[Adj_num].p_add & 0xFF;
				rebuf[6] = var[gAdj_Info[Adj_num].p_add * 2];
				rebuf[7] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
				rebuf[8] = var[gAdj_Info[Adj_num].p_add * 2 + 2];
				rebuf[9] = var[gAdj_Info[Adj_num].p_add * 2 + 3];
				rebuf[10] = var[gAdj_Info[Adj_num].p_add * 2 + 4];
				rebuf[11] = var[gAdj_Info[Adj_num].p_add * 2 + 5];
				rebuf[12] = var[gAdj_Info[Adj_num].p_add * 2 + 6];
				rebuf[13] = var[gAdj_Info[Adj_num].p_add * 2 + 7];
				LT_SendData_CRC_Frame(rebuf, 11);
			}
		}

		if (gAdj_Info[Adj_num].id != 0xFFFF)
		{
			Display_Icon(gAdj_Info[Adj_num].id, gAdj_Info[Adj_num].Xs, gAdj_Info[Adj_num].Ys, 0);
		}
		button_Press_flag = 0;
		Adj_flag = 0;
		Adj_loop = 0;
		Adj_time = 0;
		if (gAdj_Info[Adj_num].p_add >= VAR_ADDR)
		{
			reg_operation(gAdj_Info[Adj_num].p_add);
		}
		page_date_update(pic_id);
		if(pic_id==27)
		{
			Get_date_variable_Id_Regular_update(pic_id);Mode_I_Sum = sum;
		}			
		else if(pic_id==29)
		{
			Get_date_variable_Id_Regular_update(pic_id);Mode_II_Sum = sum;
		}			
		else if(pic_id==31)
		{
			Get_date_variable_Id_Regular_update(pic_id);Mode_III_Sum = sum;		
		}			
		if(pic_id==33)
		{
			PWM_WriteGpioData(PWM_PORT0, 0);
			//DelayMS(1000);
			Count_value_show_flag = TRUE;
		}
		
		if(Count_value_show_flag&&Count_value_show_delay==100)
		{
			Count_value_show_flag = FALSE;
			Count_value_show_delay = 0;	
			Count_value_to_Zero();
		}
		
		if(pic_id==18)	
		{
			if(Adj_num==3)
			{
				Lmode_flag = IO_READ8(Lock_mode1_sAddr);
				if(Lmode_flag==0)	Lmode_flag=1;
				else	Lmode_flag=0;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[17] = Lmode_flag;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();	
				var[0x1025*2+1]=Lmode_flag;
				printf("var[0x1025*2+1] = %d \r\n",var[0x1025*2+1]);
				printf("Lmode_flag = %d \r\n",Lmode_flag);
			}
			else if(Adj_num==2)
			{
				Lmode_flag = IO_READ8(Lock_mode2_sAddr);
				if(Lmode_flag==0)	Lmode_flag=1;
				else	Lmode_flag=0;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[18] = Lmode_flag;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();	
				var[0x1026*2+1]=Lmode_flag;	
				printf("var[0x1026*2+1] = %d \r\n",var[0x1026*2+1]);	
				printf("Lmode_flag = %d \r\n",Lmode_flag);		
			}
			else if(Adj_num==1)
			{
				Lmode_flag = IO_READ8(Lock_mode3_sAddr);
				if(Lmode_flag==0)	Lmode_flag=1;
				else	Lmode_flag=0;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[19] = Lmode_flag;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();	
				var[0x1027*2+1]=Lmode_flag;	
			    printf("var[0x1027*2+1] = %d \r\n",var[0x1027*2+1]);
				printf("Lmode_flag = %d \r\n",Lmode_flag);				
			}
			else if(Adj_num==0)
			{
				Lmode_flag = IO_READ8(Lock_mode4_sAddr);
				if(Lmode_flag==0)	Lmode_flag=1;
				else	Lmode_flag=0;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[20] = Lmode_flag;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();	
				var[0x1028*2+1]=Lmode_flag;	
				printf("var[0x1028*2+1] = %d \r\n",var[0x1028*2+1]);
				printf("Lmode_flag = %d \r\n",Lmode_flag);				
			}
			Get_date_variable_Id_Regular_update(pic_id);		
		}			
		
		if(gAdj_Info[Adj_num].p_add==0x1101)
		{
				EFLASH_SetWritePermission();
				W_buff[29] = var[0x1101*2+1];
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				JiLiang_tiao_state = IO_READ8(JiLiang_tiao_sAddr);
			  printf("0x1101 -- %d\n",JiLiang_tiao_state);
				EFLASH_ClrWritePermission();
		}
		
		if(gAdj_Info[Adj_num].p_add==0x2010)
		{
			EFLASH_SetWritePermission();
			W_buff[12] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
			EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
			Sleep_time_state = IO_READ8(Sleep_Time_sAddr);
			printf("0x2010 -- %d\n",Sleep_time_state);
			EFLASH_ClrWritePermission();
		}
		
		if(gAdj_Info[Adj_num].p_add==0x0275)
		{
			EFLASH_SetWritePermission();
			W_buff[0] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
			EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
			pageSTART_flag = IO_READ8(pageSTART_sAddr);
			printf("0x0275 -- %d\n",pageSTART_flag);
			EFLASH_ClrWritePermission();
		}
		
		if(gAdj_Info[Adj_num].p_add==0x1048)
		{
			EFLASH_SetWritePermission();
			W_buff[9] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
			EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
			printf("0x1048 -- %d\n",IO_READ8(Touch_sAddr));
			EFLASH_ClrWritePermission();
			
			if(IO_READ8(Touch_sAddr))
				Touch_flag = 1;
			else
				Touch_flag = 0;
		}
		
		if(gAdj_Info[Adj_num].p_add==0x1049)
		{
			EFLASH_SetWritePermission();
			W_buff[10] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
			EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
			printf("0x1049 -- %d\n",IO_READ8(Button_sAddr));
			EFLASH_ClrWritePermission();
			
			if(IO_READ8(Button_sAddr))
				Button_flag = 1;
			else
				Button_flag = 0;
		}
		
		if(gAdj_Info[Adj_num].p_add==0x1900)
		{
			EFLASH_SetWritePermission();
			W_buff[11] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
			EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
			Language_state = IO_READ8(Language_sAddr);
			printf("0x1900 -- %d\n",Language_state);
			EFLASH_ClrWritePermission();
		}
		if(gAdj_Info[Adj_num].p_add==0x2001)
		{
			EFLASH_SetWritePermission();
			W_buff[21] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
			EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
			Backlight_state = IO_READ8(Backlight_sAddr);
			printf("0x2001 -- %d\n",Backlight_state);
			EFLASH_ClrWritePermission();
		}
		
		if(gAdj_Info[Adj_num].p_add==0x0201)
		{
				EFLASH_SetWritePermission();
				W_buff[22] = sum>>8& 0XFF;
				W_buff[23] = sum & 0XFF;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
		}
		
		if(gAdj_Info[Adj_num].p_add==0x0211)
		{
				EFLASH_SetWritePermission();
				W_buff[24] = sum>>8& 0XFF;
				W_buff[25] = sum & 0XFF;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
		}
		
		if(gAdj_Info[Adj_num].p_add==0x0221)
		{
				EFLASH_SetWritePermission();
				W_buff[26] = sum>>8& 0XFF;
				W_buff[27] = sum & 0XFF;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
		}
	}
}

/***********************************************************************************
 * Function Name : VarKey_touch
 * Description   : Touch detection of multivariable adjustment.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void VarKey_touch(void)
{
	uint8_t i = 0;
	uint8_t rebuf[50];
	uint8_t Ebuff[1];
	uint8_t Buff[8]={0};
	uint16_t value = 0;
	// press down
	if (gTpInfo.sta)
	{
		Var_loop_flag = TRUE;
		for (i = 0; i < VarKey_count; i++)
		{
			if (gTpInfo.x[0] >= gVarKey_Info[i].Xs && gTpInfo.y[0] >= gVarKey_Info[i].Ys && gTpInfo.x[0] <= gVarKey_Info[i].Xe && gTpInfo.y[0] <= gVarKey_Info[i].Ye && VarKey_flag == 0 && button_Press_flag == 0)
			{
				if (gVarKey_Info[i].press_id != 0xFFFF)
				{
					Display_Icon(gVarKey_Info[i].press_id, gVarKey_Info[i].Xs, gVarKey_Info[i].Ys, 0);
				}
				
				VarKey_num = i;
				VarKey_flag = 1;
				button_Press_flag = 1;
				if (buzzer)
					touch_buzzer();				
			}
		}
	}
	else
	{
		Var_time = 0;
		Var_loop_flag = FALSE;
	}
	
	if (Var_time>255)
	{
		VarKey_flag = 0;
		button_Press_flag = 0;
		if(var[0x0202 * 2 + 1]==0)
		{
			if(pic_id==28)     
				Display_page(27);
		}

		if(var[0x0212 * 2 + 1]==0)
		{
			if(pic_id==30)      
			Display_page(29);
		}

		if(var[0x0222 * 2 + 1]==0)
		{
		  if(pic_id==32)     
			Display_page(31);
		}

	}
	
	if (gTpInfo.sta == 0 && VarKey_flag == 1)
	{
		if (gVarKey_Info[VarKey_num].id != 0xFFFF)
		{
			Display_Icon(gVarKey_Info[VarKey_num].id, gVarKey_Info[VarKey_num].Xs, gVarKey_Info[VarKey_num].Ys, 0);
		}
		button_Press_flag = 0;
		VarKey_flag = 0;
		if((Lock_flag&&((pic_id==1||pic_id==27||pic_id==29||pic_id==31)
			&&((IO_READ8(Lock_mode1_sAddr)&&VarKey_num==3)||(IO_READ8(Lock_mode2_sAddr)&&VarKey_num==2)||(IO_READ8(Lock_mode3_sAddr)&&VarKey_num==0)
		||(IO_READ8(Lock_mode4_sAddr)&&VarKey_num==1))))
		||(IO_READ8(Touch_sAddr)==0&&((pic_id==27&&VarKey_num==3)||(pic_id==28)||(pic_id==29&&VarKey_num==2)||(pic_id==31&&VarKey_num==0))))
		{

		}		
		else
		{
			if(pic_id==27||pic_id==29||pic_id==31||pic_id==1)
			{
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				if(VarKey_num==3)
				{			
					W_buff[30] = 1;
				}
				else if(VarKey_num==2)
				{
					W_buff[30] = 2;
				}					
				else if(VarKey_num==0)
				{
					W_buff[30] = 3;
				}					
				else if(VarKey_num==1)
				{
					W_buff[30] = 4;
				}					
				Ye_Mian_num = W_buff[30];	
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
			}
			
			if(pic_id==33)
			{
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				if(VarKey_num==0)
					W_buff[30] = 3;
				else if(VarKey_num==1)
					W_buff[30] = 2;
				else if(VarKey_num==2)
					W_buff[30] = 1;
				Ye_Mian_num = W_buff[30];	
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();	
			}
			
			if((pic_id==27)&&VarKey_num==3)	
			{
				Mode1_count++;
				Mode1_count_ALL++;
				value = ((uint32_t)IO_READ8(OneCupH_sAddr)<<8) + IO_READ8(OneCupL_sAddr) + 1;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[1] = value>>8;
				W_buff[2] = value & 0XFF;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
			}
			if((pic_id==29)&&VarKey_num==2)	
			{
				Mode2_count++;
				Mode2_count_ALL++;
				value = ((uint32_t)IO_READ8(TwoCupH_sAddr)<<8) + IO_READ8(TwoCupL_sAddr) + 1;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[3] = value>>8;
				W_buff[4] = value & 0XFF;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();			
			}
			if((pic_id==31)&&VarKey_num==0)
			{
				Mode3_count++;
				Mode3_count_ALL++;
				value = ((uint32_t)IO_READ8(ThreeCupH_sAddr)<<8) + IO_READ8(ThreeCupL_sAddr) + 1;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				W_buff[5] = value>>8;
				W_buff[6] = value & 0XFF;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();				
			}			
			if((pic_id==2&&VarKey_num==1))	
			{
				W_buff[1] = 0;
				W_buff[2] = 0;
				W_buff[3] = 0;
				W_buff[4] = 0;
				W_buff[5] = 0;
				W_buff[6] = 0;
				W_buff[7] = 0;
				W_buff[8] = 0;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();	 
				Mode1_count=0;Mode2_count=0;Mode3_count=0;Count_value=0;
				Display_page(2);
			}			
									
			if((pic_id==26)&&VarKey_num==1||Reset_flag==1)//复位
			{			
				W_buff[0] = 1;
				W_buff[1] = 0;
				W_buff[2] = 0;
				W_buff[3] = 0;
				W_buff[4] = 0;
				W_buff[5] = 0;
				W_buff[6] = 0;
				W_buff[7] = 0;
				W_buff[8] = 0;
				W_buff[9] = 1;
				W_buff[10] = 1;
				W_buff[11] = 1;
				W_buff[12] = 5;
				W_buff[13] = 0;
				W_buff[14] = 0;
				W_buff[15] = 0;
				W_buff[16] = 0;
				W_buff[17] = 0;
				W_buff[18] = 0;
				W_buff[19] = 0;
				W_buff[20] = 0;
				W_buff[21] = 21;
				W_buff[22] = 3000>>8;	 
				W_buff[23] = 3000&0xff;				
				W_buff[24] = 6000>>8;  
				W_buff[25] = 6000&0xff;
				W_buff[26] = 9000>>8;  
				W_buff[27] = 9000&0xff;
				W_buff[28] = 0;
				W_buff[29] = 0;
				W_buff[30] = 0;
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();	 
				var[0x1900 * 2 + 1]=1;
				var[0x200e*2+1] = 0;
				//var[0x200f*2+1] = Sleep_time_state;
				Sleep_flag = 0;
				var[0x2010*2] = 0;       
				var[0x2010*2+1] = 5;
				var[0x0201*2] = 3000>>8;
				var[0x0201*2+1] = 3000&0xff;
				var[0x0211*2] = 6000>>8;
				var[0x0211*2+1] = 6000&0xff;	
				var[0x0221*2] = 9000>>8;
				var[0x0221*2+1] = 9000&0xff;	
				Mode_I_Sum = (var[0x0201 * 2] << 8) | var[0x0201 * 2 + 1];
				Mode_II_Sum = (var[0x0211 * 2] << 8) | var[0x0211 * 2 + 1];
				Mode_III_Sum = (var[0x0221 * 2] << 8) | var[0x0221 * 2 + 1];	
				Count_value = 0;
				Ye_Mian_num = 0;
			    Touch_flag = 1;
				var[0x1048*2] = 0;
				var[0x1048*2+1] = Touch_flag;
				Button_flag = 1;
				Lock_mark_flag = 0;
				var[0x1049*2] = 0;
				var[0x1049*2+1] = Button_flag;
				var[0x0A08*2] = 0;
				var[0x0A08*2+1] = 0;
				Language_state = 1;
				Backlight_count = 0;
				Backlight_state = 21;
				var[VAR_BL * 2 + 1] = Backlight_state;
				LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
				Sleep_time_state = 0;
				pageSTART_flag = 1;
				var[0x0275*2] = 0x00;
				var[0x0275*2+1] = 1;
				JiLiang_tiao_state = 1;
				var[0x1101*2] = 0;
				var[0x1101*2+1] = JiLiang_tiao_state;
				Long_press_lock = 0;
				Password_flag=0;
				Reset_flag=0;
          //printf("GGGGGGGGGGGGGGGGGGGGG88\r\n");
			}

			for (i = 0; i < 8; i++)
			{
				if (gVarKey_Info[VarKey_num].var_addr[i] != 0xFFFF && gVarKey_Info[VarKey_num].var_addr[i] <= VAR_ADDR_E)
				{
					var[gVarKey_Info[VarKey_num].var_addr[i] * 2] = (gVarKey_Info[VarKey_num].var[i] >> 8) & 0xFF;
					var[gVarKey_Info[VarKey_num].var_addr[i] * 2 + 1] = gVarKey_Info[VarKey_num].var[i] & 0xFF;

					if (gVarKey_Info[VarKey_num].var_addr[i] >= VAR_ADDR_S)
					{
						reg_operation(gVarKey_Info[VarKey_num].var_addr[i]);
					}
				}
			}
			if (gVarKey_Info[VarKey_num].Code == 0xC00B)
			{
				rebuf[0] = 0x41;
				for (i = 0; i < 8; i++)
				{
					rebuf[4 * i + 1] = gVarKey_Info[VarKey_num].var_addr[i] >> 8;
					rebuf[4 * i + 2] = gVarKey_Info[VarKey_num].var_addr[i] & 0xFF;
					rebuf[4 * i + 3] = gVarKey_Info[VarKey_num].var[i] >> 8;
					rebuf[4 * i + 4] = gVarKey_Info[VarKey_num].var[i] & 0xFF;
				}
				LT_SendData_CRC_Frame(rebuf, 33);
			}
					
			 if((pic_id==4&&VarKey_num==1)||(pic_id==6&&VarKey_num==1))	//进入密码界面
			{
				if(IO_READ8(Password_Flag_sAddr)==0)	//判断密码状态
				{
					gVarKey_Info[VarKey_num].Next_id = 5;
				}
				else	gVarKey_Info[VarKey_num].Next_id = 7;
			}	
			
			
			
		  	if((pic_id==15&&VarKey_num==1)||(pic_id==18&&VarKey_num==2))//进入待机界面
			{
				if(Sleep_flag==0)
				{
					gVarKey_Info[VarKey_num].Next_id = 16;    
				}
				else
					gVarKey_Info[VarKey_num].Next_id = 41;       
									
			}	
			
			if((pic_id==16&&VarKey_num==1))	//待机
			{
				EFLASH_SetWritePermission();
				W_buff[16] = 1;
				Sleep_flag = 1;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
				if (Backlight_flag == 0)
				{	
					Backlight_count = 0;								
					Backlight_flag = 1;
				}
			}	
			if((pic_id==41&&VarKey_num==1))	//不待机
			{
				EFLASH_SetWritePermission();
				W_buff[16] = 0;
				Sleep_flag = 0;
				EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
				EFLASH_ClrWritePermission();
				Backlight_count = 0;								
				Backlight_flag = 0;
			}	
			
			
			if (gVarKey_Info[VarKey_num].Next_id != 0xFFFF)
			{
				Display_page(gVarKey_Info[VarKey_num].Next_id);
			}
				
		}

			if((pic_id==2||pic_id==3||pic_id==4||pic_id==5||pic_id==6||pic_id==10||pic_id==12//屏保及菜单退回记忆页面
				||pic_id==14||pic_id==15||pic_id==16||pic_id==18||pic_id==22||pic_id==23
			    ||pic_id==24||pic_id==25||pic_id==26||pic_id==41
			    ||pic_id==17||pic_id==7||pic_id==20)&&VarKey_num==0)
			{
				//printf("1111--Ye_Mian_num = %d \r\n",Ye_Mian_num);
				show_YeMian(); 
				var[0x1A40*2+1]=0;
				var[0x1A41*2+1]=0;
			}

	}
}

#define GESTURE_THRESHOLD 50	  // Gesture effective sliding threshold
uint8_t Gesture_press = 0;		  // Gesture effective press/release
uint8_t Gesture_direction = 0xFF; // Gesture direction
uint8_t Gesture_flag = 0;		  // Gesture function on/off
/***********************************************************************************
 * Function Name : Gesture_touch
 * Description   : Touch detection of gesture.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Gesture_touch(void)
{
	uint8_t i = 0;
	int16_t Gesture_X, Gesture_Y;
	uint8_t rebuf[20];

	// press down
	if (gTpInfo.sta && Gesture_press == 0)
	{
		Gesture_press = 1;
	}

	// raise
	if (gTpInfo.sta == 0 && Gesture_press == 1)
	{
		Gesture_press = 0;
		Gesture_X = gTpInfo.x[0] - First_pressX;
		Gesture_Y = gTpInfo.y[0] - First_pressY;
		if (Gesture_X >= GESTURE_THRESHOLD || Gesture_X <= -GESTURE_THRESHOLD || Gesture_Y >= GESTURE_THRESHOLD || Gesture_Y <= -GESTURE_THRESHOLD)
		{
			if (abs(Gesture_Y) > abs(Gesture_X))
			{
				if (Gesture_Y < 0)
					Gesture_direction = 0; // up
				else
					Gesture_direction = 1; // down
			}
			else
			{
				if (Gesture_X < 0)
					Gesture_direction = 2; // left
				else
					Gesture_direction = 3; // right
			}
		}

		if (Gesture_direction != 0xFF)
		{
			if (gGesture_Info.page[Gesture_direction] != 0xFFFF)
			{
				Gesture_flag = 0;
				if (gGesture_Info.Code == 0xC000)
				{
					rebuf[3] = 0x41;
					rebuf[4] = 0xFF;
					rebuf[5] = 0xFF;
					rebuf[6] = (gGesture_Info.value[Gesture_direction] >> 8) & 0xFF;
					rebuf[7] = gGesture_Info.value[Gesture_direction] & 0xFF;
					LT_SendData_CRC_Frame(rebuf, 5);
				}
				Display_page(gGesture_Info.page[Gesture_direction]);
			}

			Gesture_direction = 0xFF;
		}
	}
}

/***********************************************************************************
 * Function Name : Disp_slide
 * Description   : Display sliding progress bar.
 * Input         : - i: which number of sliding progress bar
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Disp_slide(uint8_t i)
{
	uint8_t buff[12] = {0};
	int16_t sum = 0;
	uint16_t w, h;
	uint16_t dw = 0, dh = 0, dw1 = 0, dh1 = 0, bgw, bgh;
	uint16_t xyoff;
	
	// progress bar is empty
	if (gSlide_Info[i].slideid == 0xFFFF) return;
	
	// touch icon
	if (gSlide_Info[i].arrowid != 0xFFFF)
	{
		LT_ReadFlash(buff, addr_index[10] + 12 * gSlide_Info[i].arrowid, 12);
		pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		dw = buff[4] + (buff[5] << 8);
		dh = buff[6] + (buff[7] << 8);

		PICINFO[2].addr = pic_add;
		PICINFO[2].w = dw;
		PICINFO[2].h = dh;
		PICINFO[2].flag = buff[11];
	}
	else
	{
		dw = 0;
		dh = 0;
		PICINFO[2].w = 0;
		PICINFO[2].h = 0;
	}

	// progress bar
	LT_ReadFlash(buff, addr_index[10] + 12 * gSlide_Info[i].slideid, 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	pic_w = buff[4] + (buff[5] << 8);
	pic_h = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

	dw1 = pic_w;
	dh1 = pic_h;
	PICINFO[1].addr = pic_add;
	PICINFO[1].w = pic_w;
	PICINFO[1].h = pic_h;
	PICINFO[1].flag = pic_flag;

	// progress bar background
	if (gSlide_Info[i].bgid != 0xFFFF)
	{

		LT_ReadFlash(buff, addr_index[10] + 12 * gSlide_Info[i].bgid, 12);
		pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		bgw = buff[4] + (buff[5] << 8);
		bgh = buff[6] + (buff[7] << 8);
		pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		pic_flag = buff[11];

		PICINFO[0].addr = pic_add;
		PICINFO[0].w = bgw;
		PICINFO[0].h = bgh;
		PICINFO[0].flag = pic_flag;
		PICINFO[0].x = gSlide_Info[i].x1;
		PICINFO[0].y = gSlide_Info[i].y1;
		
		// full-screen background
		if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
		{
			LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
								PICINFO[0].x, PICINFO[0].y, LCD_XSIZE_TFT, FullScreen_addr,
								PICINFO[0].w, PICINFO[0].h, 0);
		}

		// progress bar
		LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
							0, 0, PICINFO[0].w, PICINFO[0].addr,
							PICINFO[0].w, PICINFO[0].h, PICINFO[0].flag);

		// progress bar
		PICINFO[1].x = gSlide_Info[i].x2 - gSlide_Info[i].x1;
		PICINFO[1].y = gSlide_Info[i].y2 - gSlide_Info[i].y1;

		// touch icon
		if (gSlide_Info[i].direction == 0 || gSlide_Info[i].direction == 1)
		{
			if (PICINFO[2].h < PICINFO[1].h)
				PICINFO[2].y = PICINFO[1].y + (PICINFO[1].h - PICINFO[2].h) / 2;
			else
				PICINFO[2].y = PICINFO[1].y - (PICINFO[2].h - PICINFO[1].h) / 2;
		}
		else if (gSlide_Info[i].direction == 2 || gSlide_Info[i].direction == 3)
		{
			if (PICINFO[2].w < PICINFO[1].w)
				PICINFO[2].x = PICINFO[1].x + (PICINFO[1].w - PICINFO[2].w) / 2;
			else
				PICINFO[2].x = PICINFO[1].x - (PICINFO[2].w - PICINFO[1].w) / 2;
		}
	}
	else
	{
		// Coordinate calculation
		if (gSlide_Info[i].direction == 0 || gSlide_Info[i].direction == 1)
		{
			PICINFO[0].w = PICINFO[1].w + dw; // max w
			PICINFO[0].x = gSlide_Info[i].x2 - dw / 2;
			PICINFO[1].x = dw / 2 ;
			if (dh < dh1) // dw,dh of touch icon
			{
				PICINFO[0].h = dh1;
				PICINFO[0].y = gSlide_Info[i].y2;
				PICINFO[1].y = 0;			   // progress bar, Y coordinate relative to buffer
				PICINFO[2].y = (dh1 - dh) / 2; // touch icon, Y coordinate relative to buffer
			}
			else
			{
				PICINFO[0].h = dh;
				PICINFO[0].y = gSlide_Info[i].y2 - (dh - dh1) / 2;
				PICINFO[1].y = (dh - dh1) / 2;
				PICINFO[2].y = 0;
			}
		}
		else if (gSlide_Info[i].direction == 2 || gSlide_Info[i].direction == 3)
		{
			PICINFO[0].h = PICINFO[1].h + dh;
			PICINFO[0].y = gSlide_Info[i].y2 - dh / 2;
			PICINFO[1].y = dh / 2;
			if (dw < dw1)
			{
				PICINFO[0].w = dw1;
				PICINFO[0].x = gSlide_Info[i].x2;
				PICINFO[1].x = 0;			   // progress bar, Y coordinate relative to buffer
				PICINFO[2].x = (dw1 - dw) / 2; // touch icon, Y coordinate relative to buffer
			}
			else
			{
				PICINFO[0].w = dw;
				PICINFO[0].x = gSlide_Info[i].x2 - (dw - dw1) / 2;
				PICINFO[1].x = (dw - dw1) / 2;
				PICINFO[2].x = 0;
			}
		}

		// full-screen background
		LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
							PICINFO[0].x, PICINFO[0].y, LCD_XSIZE_TFT, FullScreen_addr,
							PICINFO[0].w, PICINFO[0].h, 0);
	}

	switch (gSlide_Info[i].direction)
	{
		case 0: // From left to right
//			if (Slide_flag == 0)
//			{
				sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
				if (sum > gSlide_Info[i].V_max)
					sum = gSlide_Info[i].V_max;
				else if (sum < gSlide_Info[i].V_min)
					sum = gSlide_Info[i].V_min;
//				w = ((gSlide_Info[i].Xe - gSlide_Info[i].Xs + 1) * (sum - gSlide_Info[i].V_min)) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
				w = (PICINFO[1].w * (sum - gSlide_Info[i].V_min)) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}
//			else
//				w = gSlide_Info[i].dx - gSlide_Info[i].Xs;


			// progress bar
			LT268_pic_to_buffer(PICINFO[1].x, PICINFO[1].y, PICINFO[0].w, m_PngData,
								0, 0, PICINFO[1].w, PICINFO[1].addr,
								w, PICINFO[1].h, PICINFO[1].flag);

			// touch icon
			if (gSlide_Info[i].arrowid != 0xFFFF)
			{
//							printf(" sum,w,xyoff %d  %d  %d   Slide_flag %d \r\n",sum,w,xyoff,Slide_flag);

				LT268_pic_to_buffer(PICINFO[1].x + w - PICINFO[2].w / 2, PICINFO[2].y, PICINFO[0].w, m_PngData,
									0, 0, PICINFO[2].w, PICINFO[2].addr,
									PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
			}

			break;
		case 1: // From right to left
//			if (Slide_flag == 0)
//			{
				sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
				if (sum > gSlide_Info[i].V_max)
					sum = gSlide_Info[i].V_max;
				else if (sum < gSlide_Info[i].V_min)
					sum = gSlide_Info[i].V_min;

				w = (PICINFO[1].w * (sum - gSlide_Info[i].V_min)) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}
			
			// progress bar
			LT268_pic_to_buffer(PICINFO[1].x + PICINFO[1].w - w, PICINFO[1].y, PICINFO[0].w, m_PngData,
								PICINFO[1].w - w, 0, PICINFO[1].w, PICINFO[1].addr,
								w, PICINFO[1].h, PICINFO[1].flag);

			// touch icon
			if (gSlide_Info[i].arrowid != 0xFFFF)
			{
				LT268_pic_to_buffer(PICINFO[1].x + PICINFO[1].w - w - PICINFO[2].w / 2, PICINFO[2].y, PICINFO[0].w, m_PngData,
									0, 0, PICINFO[2].w, PICINFO[2].addr,
									PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
			}

			break;
		case 2: // From top to bottom
//			if (Slide_flag == 0)
//			{
				sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
				if (sum > gSlide_Info[i].V_max)
					sum = gSlide_Info[i].V_max;
				else if (sum < gSlide_Info[i].V_min)
					sum = gSlide_Info[i].V_min;

				h = (PICINFO[1].h * (sum - gSlide_Info[i].V_min)) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}
//			else
//			{
//				h = gSlide_Info[i].dy - gSlide_Info[i].Ys;
//			}

			// progress bar
			LT268_pic_to_buffer(PICINFO[1].x, PICINFO[1].y, PICINFO[0].w, m_PngData,
								0, 0, PICINFO[1].w, PICINFO[1].addr,
								PICINFO[1].w, h, PICINFO[1].flag);

			// touch icon
			if (gSlide_Info[i].arrowid != 0xFFFF)
			{
				LT268_pic_to_buffer(PICINFO[2].x, PICINFO[1].y - PICINFO[2].h / 2 + h, PICINFO[0].w, m_PngData,
									0, 0, PICINFO[2].w, PICINFO[2].addr,
									PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
			}

			break;
		case 3: // From bottom to top
//			if (Slide_flag == 0)
//			{
				sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
				if (sum > gSlide_Info[i].V_max)
					sum = gSlide_Info[i].V_max;
				else if (sum < gSlide_Info[i].V_min)
					sum = gSlide_Info[i].V_min;

				h = (PICINFO[1].h * (sum - gSlide_Info[i].V_min)) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}
//			else
//			{
//				h = gSlide_Info[i].Ye - gSlide_Info[i].dy;
//			}
//			if (h > (dh1 - gSlide_Info[i].Ys + gSlide_Info[i].y2))
//				h = dh1 - gSlide_Info[i].Ys + gSlide_Info[i].y2;

			// progress bar
			LT268_pic_to_buffer(PICINFO[1].x, PICINFO[1].y + PICINFO[1].h - h, PICINFO[0].w, m_PngData,
								0, PICINFO[1].h - h, PICINFO[1].w, PICINFO[1].addr,
								PICINFO[1].w, h, PICINFO[1].flag);

			// touch icon
			if (gSlide_Info[i].arrowid != 0xFFFF)
			{
				LT268_pic_to_buffer(PICINFO[2].x, PICINFO[1].y - PICINFO[2].h / 2 + PICINFO[1].h - h, PICINFO[0].w, m_PngData,
									0, 0, PICINFO[2].w, PICINFO[2].addr,
									PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
			}

			break;
		default:
			break;
	}

	// display
	LT268_buffer_to_TFT(0, 0, PICINFO[0].w, m_PngData,
						PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h);
//		LT268_TFT_FillColor(gSlide_Info[i].Xe,gSlide_Info[i].Ys,PICINFO[2].w/2,PICINFO[2].h,Red);
	
}

/***********************************************************************************
 * Function Name : Progress_bar_sliding
 * Description   : Touch detection of sliding progress bar.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Progress_bar_sliding(void)
{
	uint8_t i = 0, rebuf[20];
	int16_t temp;
	int32_t sum = 0;
	float step = 0;
	if (gTpInfo.sta)
	{
		for (i = 0; i < Slide_count; i++)
		{
			if (gSlide_Info[i].lastx != gTpInfo.x[0] || gSlide_Info[i].lasty != gTpInfo.y[0])
			{
				switch (gSlide_Info[i].direction)
				{
				case 0: // From left to right
					if (gTpInfo.x[0] >= gSlide_Info[i].Xs - 40 && gTpInfo.y[0] >= gSlide_Info[i].Ys &&
						gTpInfo.x[0] <= gSlide_Info[i].Xe + 40 && gTpInfo.y[0] <= gSlide_Info[i].Ye &&
						((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
					{
						if (slide_first_touch == 0)
						{
							slide_first_touch = 1;
							if (buzzer)
								touch_buzzer();
						}
						slide_num = i;
						button_Press_flag = 1;

						gSlide_Info[i].dx = gTpInfo.x[0];
						if (gTpInfo.x[0] > gSlide_Info[i].Xe)
							gSlide_Info[i].dx = gSlide_Info[i].Xe;
						else if (gTpInfo.x[0] < gSlide_Info[i].Xs)
							gSlide_Info[i].dx = gSlide_Info[i].Xs;

						step = ((float)gSlide_Info[i].V_max - (float)gSlide_Info[i].V_min) / ((float)gSlide_Info[i].Xe - (float)gSlide_Info[i].Xs);
						if (gSlide_Info[i].dx == gSlide_Info[i].Xs)
						{
							var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
						}
						else if (gSlide_Info[i].dx == gSlide_Info[i].Xe)
						{
							var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
						}
						else
						{
							temp = (gSlide_Info[i].dx - gSlide_Info[i].Xs) * step + gSlide_Info[i].V_min;
							var[gSlide_Info[i].p_add * 2] = temp >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
						}
						gSlide_Info[i].lasty = gTpInfo.y[0];
						if (gSlide_Info[i].lastx != gTpInfo.x[0])
						{
							gSlide_Info[i].lastx = gTpInfo.x[0];
							Slide_flag = 1;
						}
					}
					break;
				case 1: // From right to left
					if (gTpInfo.x[0] >= gSlide_Info[i].Xs - 40 && gTpInfo.y[0] >= gSlide_Info[i].Ys &&
						gTpInfo.x[0] <= gSlide_Info[i].Xe + 40 && gTpInfo.y[0] <= gSlide_Info[i].Ye &&
						((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
					{
						if (slide_first_touch == 0)
						{
							slide_first_touch = 1;
							if (buzzer)
								touch_buzzer();
						}
						slide_num = i;
						button_Press_flag = 1;
						gSlide_Info[i].dx = gTpInfo.x[0];
						if (gTpInfo.x[0] > gSlide_Info[i].Xe)
							gSlide_Info[i].dx = gSlide_Info[i].Xe;
						else if (gTpInfo.x[0] < gSlide_Info[i].Xs)
							gSlide_Info[i].dx = gSlide_Info[i].Xs;
						step = ((float)gSlide_Info[i].V_max - (float)gSlide_Info[i].V_min) / ((float)gSlide_Info[i].Xe - (float)gSlide_Info[i].Xs);
						if (gSlide_Info[i].dx == gSlide_Info[i].Xs)
						{
							var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
						}
						else if (gSlide_Info[i].dx == gSlide_Info[i].Xe)
						{
							var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
						}
						else
						{
							temp = (gSlide_Info[i].Xe - gSlide_Info[i].dx) * step + gSlide_Info[i].V_min;
							var[gSlide_Info[i].p_add * 2] = temp >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
						}
						gSlide_Info[i].lasty = gTpInfo.y[0];
						if (gSlide_Info[i].lastx != gTpInfo.x[0])
						{
							gSlide_Info[i].lastx = gTpInfo.x[0];
							Slide_flag = 1;
						}
					}
					break;
				case 2: // From top to bottom
					if (gTpInfo.x[0] >= gSlide_Info[i].Xs && gTpInfo.y[0] >= gSlide_Info[i].Ys - 40 &&
						gTpInfo.x[0] <= gSlide_Info[i].Xe && gTpInfo.y[0] <= gSlide_Info[i].Ye + 40 &&
						((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
					{
						if (slide_first_touch == 0)
						{
							slide_first_touch = 1;
							if (buzzer)
								touch_buzzer();
						}
						slide_num = i;
						button_Press_flag = 1;
						gSlide_Info[i].dy = gTpInfo.y[0];
						if (gTpInfo.y[0] > gSlide_Info[i].Ye)
							gSlide_Info[i].dy = gSlide_Info[i].Ye;
						else if (gTpInfo.y[0] < gSlide_Info[i].Ys)
							gSlide_Info[i].dy = gSlide_Info[i].Ys;

						step = ((float)gSlide_Info[i].V_max - (float)gSlide_Info[i].V_min) / ((float)gSlide_Info[i].Ye - (float)gSlide_Info[i].Ys);
						if (gSlide_Info[i].dy == gSlide_Info[i].Ys)
						{
							var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
						}
						else if (gSlide_Info[i].dy == gSlide_Info[i].Ye)
						{
							var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
						}
						else
						{
							temp = (gSlide_Info[i].dy - gSlide_Info[i].Ys) * step + gSlide_Info[i].V_min;
							var[gSlide_Info[i].p_add * 2] = temp >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
						}

						gSlide_Info[i].lastx = gTpInfo.x[0];
						if (gSlide_Info[i].lasty != gTpInfo.y[0])
						{
							gSlide_Info[i].lasty = gTpInfo.y[0];
							Slide_flag = 1;
						}
					}
					break;
				case 3: // From bottom to top
					if (gTpInfo.x[0] >= gSlide_Info[i].Xs && gTpInfo.y[0] >= gSlide_Info[i].Ys - 40 &&
						gTpInfo.x[0] <= gSlide_Info[i].Xe && gTpInfo.y[0] <= gSlide_Info[i].Ye + 40 &&
						((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
					{
						if (slide_first_touch == 0)
						{
							slide_first_touch = 1;
							if (buzzer)
								touch_buzzer();
						}
						slide_num = i;
						button_Press_flag = 1;
						gSlide_Info[i].dy = gTpInfo.y[0];
						if (gTpInfo.y[0] > gSlide_Info[i].Ye)
							gSlide_Info[i].dy = gSlide_Info[i].Ye;
						else if (gTpInfo.y[0] < gSlide_Info[i].Ys)
							gSlide_Info[i].dy = gSlide_Info[i].Ys;
						step = ((float)gSlide_Info[i].V_max - (float)gSlide_Info[i].V_min) / ((float)gSlide_Info[i].Ye - (float)gSlide_Info[i].Ys);
						if (gSlide_Info[i].dy == gSlide_Info[i].Ys)
						{
							var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
						}
						else if (gSlide_Info[i].dy == gSlide_Info[i].Ye)
						{
							var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
						}
						else
						{
							temp = (gSlide_Info[i].Ye - gSlide_Info[i].dy) * step + gSlide_Info[i].V_min;
							var[gSlide_Info[i].p_add * 2] = temp >> 8;
							var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
						}
						gSlide_Info[i].lastx = gTpInfo.x[0];
						if (gSlide_Info[i].lasty != gTpInfo.y[0])
						{
							gSlide_Info[i].lasty = gTpInfo.y[0];
							Slide_flag = 1;
						}
					}
					break;
				default:
					break;
				}
				if (Slide_flag == 1)
				{
					if (gSlide_Info[i].p_add >= VAR_ADDR)
						reg_operation(gSlide_Info[i].p_add);

					page_date_update(pic_id);
					Disp_slide(i);
					Slide_flag = 0;
				}
			}
		}
	}
	else if (slide_first_touch == 1)
	{
		slide_first_touch = 0;
		button_Press_flag = 0;
		if (gSlide_Info[slide_num].Code == 0xC004)
		{
			rebuf[3] = 0x41;
			rebuf[4] = gSlide_Info[slide_num].p_add >> 8;
			rebuf[5] = gSlide_Info[slide_num].p_add & 0xFF;
			rebuf[6] = var[gSlide_Info[slide_num].p_add * 2];
			rebuf[7] = var[gSlide_Info[slide_num].p_add * 2 + 1];
			LT_SendData_CRC_Frame(rebuf, 5);
		}
	}
}

RingSld_Info gRingSld_Info[RINGSLD_SIZE];
uint8_t RingSld_count = 0;
uint8_t RingSld_firsttouch = 0;
uint8_t RingSld_firstnum = 0;
/***********************************************************************************
 * Function Name : DL_RingSld
 * Description   : calculation for ring progress bar.
 * Input         : - num: which number of ring progress bar
 * Output        : None
 * Return        : None
 ************************************************************************************/
void DL_RingSld(uint8_t num)
{
	uint8_t buff[12] = {0};

	LT_ReadFlash(buff, addr_index[10] + 12 * gRingSld_Info[num].frontID, 12);
	gRingSld_Info[num].w1 = buff[4] + (buff[5] << 8);
	gRingSld_Info[num].h1 = buff[6] + (buff[7] << 8);
	gRingSld_Info[num].xR = gRingSld_Info[num].x + gRingSld_Info[num].w1 / 2;
	gRingSld_Info[num].yR = gRingSld_Info[num].y + gRingSld_Info[num].h1 / 2;
}

void RingSld_Display(uint8_t num, uint16_t angle)
{
	uint16_t xd = 0, dx = 0, dy = 0;
	uint16_t temp;
	uint16_t value = 0, ll;
	uint8_t n = 0, flag = 0, i = 0, kk = 0;
	uint32_t zk_addr;
	uint8_t buff1[12] = {0};
	uint16_t num_w, dot_w, h, canvas_numw, canvas_dotw;
	uint16_t ring_R, ring_CX, ring_CY; // circular radius,centre point

	LT_ReadFlash(buff1, addr_index[10] + 12 * gRingSld_Info[num].frontID, 12);
	pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
	pic_w = buff1[4] + (buff1[5] << 8);
	pic_h = buff1[6] + (buff1[7] << 8);
	pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
	pic_flag = buff1[11];

	gRingSld_Info[num].w1 = pic_w;
	gRingSld_Info[num].h1 = pic_h;
	gRingSld_Info[num].rm1 = pic_flag;

	if (pic_len != 0 && pic_flag != 0xFF)
	{
		LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
							0, 0, pic_w, pic_add,
							pic_w, pic_h, 0);
	}

	if (gRingSld_Info[num].arrowid != 0xFFFF)
	{
		LT_ReadFlash(buff1, addr_index[10] + 12 * gRingSld_Info[num].arrowid, 12);
		PICINFO[2].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		PICINFO[2].w = buff1[4] + (buff1[5] << 8);
		PICINFO[2].h = buff1[6] + (buff1[7] << 8);
		PICINFO[2].flag = buff1[11];

		gRingSld_Info[num].w2 = PICINFO[2].w;
		gRingSld_Info[num].h2 = PICINFO[2].h;
	}

	if (pic_w % 2)
	{
		ring_R = pic_w / 2 + 1;
		ring_CX = pic_w / 2;
		ring_CY = pic_w / 2;
	}
	else
	{
		ring_R = pic_w / 2;
		ring_CX = pic_w / 2 - 1;
		ring_CY = pic_w / 2 - 1;
	}

	if (angle >= 0 && angle <= 45)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, 0, pic_w, m_PngData, pic_w / 2, pic_h, Black);
		LT268_TFT_FillColor_Buffer2(0, 0, pic_w, m_PngData, ring_R, ring_R - 1, Black);
		for (uint16_t xx = 0; xx < ring_R; xx++)
		{
			for (uint16_t yy = ring_CY; yy < pic_h; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R - ring_R * fast_tan(angle), ring_R * 2 - 1, xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}
	else if (angle > 45 && angle < 90)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, 0, pic_w, m_PngData, pic_w / 2, pic_h, Black);
		LT268_TFT_FillColor_Buffer2(0, 0, pic_w, m_PngData, ring_R, ring_R - 1, Black);
		for (uint16_t xx = 0; xx < ring_R; xx++)
		{
			for (uint16_t yy = ring_CY; yy < pic_h; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, 0, ring_R + ring_R * fast_tan(90 - angle) - 1, xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}
	else if (angle == 90)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, 0, pic_w, m_PngData, pic_w / 2, pic_h, Black);
		LT268_TFT_FillColor_Buffer2(0, 0, pic_w, m_PngData, ring_R, ring_R - 1, Black);
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}
	else if (angle > 90 && angle <= 135)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, 0, pic_w, m_PngData, pic_w / 2, pic_h, Black);
		for (uint16_t xx = 0; xx < ring_R; xx++)
		{
			for (uint16_t yy = 0; yy < ring_R; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, 0, ring_R - ring_R * fast_tan(angle - 90), xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}
	else if (angle >= 135 && angle <= 180)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, 0, pic_w, m_PngData, pic_w / 2, pic_h, Black);
		for (uint16_t xx = 0; xx < ring_R; xx++)
		{
			for (uint16_t yy = 0; yy < ring_R; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R - ring_R * fast_tan(180 - angle), 0, xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}
	else if (angle >= 180 && angle <= 225)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, ring_CY + 1, pic_w, m_PngData, pic_w / 2, pic_h / 2, Black);
		for (uint16_t xx = ring_CX; xx < pic_w; xx++)
		{
			for (uint16_t yy = 0; yy < ring_R; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R + ring_R * fast_tan(angle - 180), 0, xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}
	else if (angle >= 225 && angle < 270)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, ring_CY + 1, pic_w, m_PngData, pic_w / 2, pic_h / 2, Black);
		for (uint16_t xx = ring_CX; xx < pic_w; xx++)
		{
			for (uint16_t yy = 0; yy < ring_R; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R * 2 - 1, ring_R - ring_R * fast_tan(270 - angle), xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}
	else if (angle == 270)
	{
		LT268_TFT_FillColor_Buffer2(ring_CX + 1, ring_CY + 1, pic_w, m_PngData, pic_w / 2, pic_h / 2, Black);
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}
	else if (angle > 270 && angle <= 315)
	{
		for (uint16_t xx = ring_CX + 1; xx < pic_w; xx++)
		{
			for (uint16_t yy = ring_CY; yy < pic_h; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R * 2 - 1, ring_R + ring_R * fast_tan(angle - 270), xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}
	else if (angle >= 315 && angle < 360)
	{
		for (uint16_t xx = ring_CX + 1; xx < pic_w; xx++)
		{
			for (uint16_t yy = ring_CY; yy < pic_h; yy++)
			{
				if (line_k_compare(ring_CX, ring_CY, ring_R + ring_R * fast_tan(360 - angle), ring_R * 2 - 1, xx, yy))
					LT268_TFT_DrawPoint_Buffer(xx, yy, Black, pic_w);
			}
		}
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}
	else if (angle == 360)
	{
		gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle) - gRingSld_Info[num].w2 / 2;
		gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle) - gRingSld_Info[num].h2 / 2;
	}

	if (gRingSld_Info[num].bgID <= addr_index[11])
	{
		LT_ReadFlash(buff1, addr_index[10] + 12 * gRingSld_Info[num].bgID, 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
								0, 0, pic_w, pic_add,
								pic_w, pic_h, 0xF0);
		}
	}

	if (pic_flag == 1 || pic_flag == 2)
	{
		LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
							gRingSld_Info[num].x, gRingSld_Info[num].y, LCD_XSIZE_TFT, FullScreen_addr,
							pic_w, pic_h, 0xF1);
	}

	if (gRingSld_Info[num].arrowid != 0xFFFF)
	{
		LT268_pic_to_buffer(gRingSld_Info[num].x2, gRingSld_Info[num].y2, gRingSld_Info[num].w1, m_PngData,
							0, 0, PICINFO[2].w, PICINFO[2].addr,
							PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
	}

	if (gRingSld_Info[num].flag == 1)
	{
		LT_ReadFlash(buff1, addr_index[2] + gRingSld_Info[num].zk_id * 8, 4);
		zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		value = (var[gRingSld_Info[num].p_add * 2] << 8) + var[gRingSld_Info[num].p_add * 2 + 1];
		ll = pow(10, gRingSld_Info[num].I_num + gRingSld_Info[num].D_num);
		value = value % ll;
		ll = value;
		do
		{ // Get the number of digits
			n++;
			ll /= 10;
		} while (ll > 0);
		memset(Display_buff, 0, 20);

		// With decimal point
		if (gRingSld_Info[num].D_num > 0)
		{
			// All decimals
			if (gRingSld_Info[num].D_num >= n)
			{
				Display_buff[0] = '0';
				Display_buff[1] = '.';
				sprintf(&Display_buff[2], "%d", value);
			}
			else
			{
				sprintf(Display_buff, "%d", value);
				for (i = 0; i < gRingSld_Info[num].D_num; i++)
				{
					Display_buff[n - i] = Display_buff[n - 1 - i];
				}
				Display_buff[n - gRingSld_Info[num].D_num] = '.';
			}
		}
		else
		{
			sprintf(Display_buff, "%d", value);
		}

		LT_ReadFlash(buff1, zk_addr, 4);

		LT_Print_zk_Font_BUFF(4, zk_addr,
							  LAY_BUFF1, LCD_XSIZE_TFT, buff1[2], buff1[3], gRingSld_Info[num].Alig, gRingSld_Info[num].color, Black, 0,
							  gRingSld_Info[num].w1, gRingSld_Info[num].h1, m_PngData, gRingSld_Info[num].dx - gRingSld_Info[num].x, gRingSld_Info[num].dy - gRingSld_Info[num].y,
							  0, 0, Display_buff, sizeof(Display_buff));
	}
	else if (gRingSld_Info[num].flag == 2)
	{
		value = (var[gRingSld_Info[num].p_add * 2] << 8) + var[gRingSld_Info[num].p_add * 2 + 1];

		value = value % ((int)pow(10, gRingSld_Info[num].I_num + gRingSld_Info[num].D_num));

		for (i = 0; i < gRingSld_Info[num].I_num; i++) // All integers
		{

			Display_buff[kk] = value / (int)pow(10, gRingSld_Info[num].I_num - i - 1 + gRingSld_Info[num].D_num);

			if (Display_buff[kk] != 0 || flag == 1)
			{
				kk++;
				flag = 1; // The first place is not 0
			}
			value = value % (int)pow(10, gRingSld_Info[num].I_num - i - 1 + gRingSld_Info[num].D_num);
		}

		if (gRingSld_Info[num].D_num > 0)
		{
			if (flag == 0)
			{
				Display_buff[kk] = 0; //"."
				kk++;
			}
			Display_buff[kk] = 10; //"."
			kk++;
		}
		else
		{
			if (flag == 0)
			{
				Display_buff[kk] = 0; //"."
				kk++;
			}
		}
		for (i = 0; i < gRingSld_Info[num].D_num; i++) // Decimal
		{
			Display_buff[kk] = value / (int)pow(10, gRingSld_Info[num].D_num - i - 1);
			kk++;
			value = value % (int)pow(10, i - 1 + gRingSld_Info[num].D_num);
		}

		LT_ReadFlash(buff1, addr_index[10] + 12 * gRingSld_Info[num].s_id, 12);
		PICINFO[0].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		PICINFO[0].w = buff1[4] + (buff1[5] << 8);
		PICINFO[0].h = buff1[6] + (buff1[7] << 8);
		PICINFO[0].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		PICINFO[0].flag = buff1[11];
		num_w = PICINFO[0].w;

		if (gRingSld_Info[num].D_num > 0) // With decimal point
		{

			LT_ReadFlash(buff1, addr_index[10] + 12 * (gRingSld_Info[num].s_id + 10), 12);
			PICINFO[1].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			PICINFO[1].w = buff1[4] + (buff1[5] << 8);
			PICINFO[1].h = buff1[6] + (buff1[7] << 8);
			PICINFO[1].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
			PICINFO[1].flag = buff1[11];
			dot_w = PICINFO[1].w;
		}

		xd = 0;
		for (i = 0; i < kk; i++)
		{
			if (Display_buff[i] >= 0 && Display_buff[i] <= 9)
			{
				LT_ReadFlash(buff1, addr_index[10] + 12 * (gRingSld_Info[num].s_id + Display_buff[i]), 5);
				num_w = buff1[4] + (buff1[5] << 8);
				xd += num_w;
			}
			else if (Display_buff[i] == 10)
			{
				xd += dot_w;
			}
		}
		if (gRingSld_Info[num].Alig == 0)
			dx = gRingSld_Info[num].dx - gRingSld_Info[num].x;
		else if (gRingSld_Info[num].Alig == 1)
			dx = gRingSld_Info[num].dx - gRingSld_Info[num].x - xd / 2;
		else if (gRingSld_Info[num].Alig == 2)
			dx = gRingSld_Info[num].dx - gRingSld_Info[num].x - xd + 1;

		dy = gRingSld_Info[num].dy - gRingSld_Info[num].y;

		// buffer picture
		for (i = 0; i < kk; i++)
		{
			if (Display_buff[i] >= 0 && Display_buff[i] <= 9)
			{
				LT268_pic_to_buffer(dx, dy, pic_w, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr + PICINFO[0].w * PICINFO[0].h * 2 * Display_buff[i],
									PICINFO[0].w, PICINFO[0].h, PICINFO[0].flag);

				LT_ReadFlash(buff1, addr_index[10] + 12 * (gRingSld_Info[num].s_id + Display_buff[i]), 5);
				num_w = buff1[4] + (buff1[5] << 8);
				dx += num_w;
			}
			else if (Display_buff[i] == 10)
			{
				LT268_pic_to_buffer(dx, dy, pic_w, m_PngData,
									0, 0, PICINFO[1].w, PICINFO[1].addr,
									PICINFO[1].w, PICINFO[1].h, PICINFO[1].flag);
				dx += dot_w;
			}
		}
	}

	LT268_buffer_to_TFT(0, 0, pic_w, m_PngData,
						gRingSld_Info[num].x, gRingSld_Info[num].y, pic_w, pic_h);
}

/***********************************************************************************
 * Function Name : RingSld_touch
 * Description   : Touch detection of ring progress bar.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void RingSld_touch(void)
{
	uint8_t i;
	uint8_t rebuf[20];
	float Xa, Ya, Xb, Yb, Xc, Yc = 0;
	int32_t x1, y1, x2, y2;
	uint16_t angle = 0, j = 0, V = 0;

	if (gTpInfo.sta)
	{
		for (i = 0; i < RingSld_count; i++)
		{
			if(lastx != gTpInfo.x[0] || lasty != gTpInfo.y[0])
			{
				x1 = gTpInfo.x[0] - gRingSld_Info[i].xR;
				y1 = gTpInfo.y[0] - gRingSld_Info[i].yR;
				
				if (x1 * x1 + y1 * y1 >= (gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R) * (gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R) &&
					x1 * x1 + y1 * y1 <= (gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R) * (gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R) &&
					((RingSld_firsttouch == 0 && button_Press_flag == 0) || (RingSld_firsttouch == 1 && RingSld_firstnum == i)))
				{
					
					lastx = gTpInfo.x[0];
					lasty = gTpInfo.y[0];
					
					if (RingSld_firsttouch == 0 || RingSld_firstnum != i)
					{
						if (buzzer)
							touch_buzzer();
						button_Press_flag = 1;
						RingSld_firsttouch = 1;
						RingSld_firstnum = i;
						DL_RingSld(i);
					}
					// 180 to 270 degrees
					if (gTpInfo.x[0] >= gRingSld_Info[i].xR &&
						gTpInfo.x[0] <= gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R &&
						gTpInfo.y[0] >= gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R &&
						gTpInfo.y[0] <= gRingSld_Info[i].yR)
					{
						if (gTpInfo.x[0] == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(0)) ||
							gTpInfo.x[0] - 1 == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(0)))
						{
							angle = 180;
						}
						else if (gTpInfo.y[0] == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(90)) ||
								 gTpInfo.y[0] + 1 == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(90)))
						{
							angle = 270;
						}
						else
						{
							for (j = 1; j < 90; j++)
							{
								Xa = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j - 1));
								Ya = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j - 1));
								Xb = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j));
								Yb = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j));
								Xc = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j + 1));
								Yc = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j + 1));
								if (Xb * Xb + Yb * Yb <= Xa * Xa + Ya * Ya && Xb * Xb + Yb * Yb <= Xc * Xc + Yc * Yc)
								{
									angle = j + 180;
									break;
								}
							}
						}
					}
					// 270 to 360 degrees
					else if (gTpInfo.x[0] >= gRingSld_Info[i].xR && gTpInfo.x[0] <= gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R &&
							 gTpInfo.y[0] >= gRingSld_Info[i].yR && gTpInfo.y[0] <= gRingSld_Info[i].yR + gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R)
					{

						if (gTpInfo.x[0] == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(180)))
						{
							angle = 0;
						}
						else if (gTpInfo.y[0] == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(90)) ||
								 gTpInfo.y[0] - 1 == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(90)))
						{
							angle = 270;
						}
						else
						{
							for (j = 91; j < 180; j++)
							{
								Xa = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j - 1));
								Ya = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j - 1));
								Xb = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j));
								Yb = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j));
								Xc = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j + 1));
								Yc = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j + 1));
								if (Xb * Xb + Yb * Yb <= Xa * Xa + Ya * Ya && Xb * Xb + Yb * Yb <= Xc * Xc + Yc * Yc)
								{
									angle = j + 180;
									break;
								}
							}
						}
					}
					// 0 to 90 degrees
					else if (gTpInfo.x[0] >= gRingSld_Info[i].xR - gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R && gTpInfo.x[0] <= gRingSld_Info[i].xR &&
							 gTpInfo.y[0] >= gRingSld_Info[i].yR && gTpInfo.y[0] <= gRingSld_Info[i].yR + gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R)
					{
						if (gTpInfo.x[0] == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(180)))
						{
							angle = 0;
						}
						else if (gTpInfo.y[0] == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(270)) ||
								 gTpInfo.y[0] - 1 == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(270)))
						{
							angle = 90;
						}
						else
						{
							for (j = 181; j < 270; j++)
							{
								Xa = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j - 1));
								Ya = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j - 1));
								Xb = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j));
								Yb = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j));
								Xc = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j + 1));
								Yc = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j + 1));
								if (Xb * Xb + Yb * Yb <= Xa * Xa + Ya * Ya && Xb * Xb + Yb * Yb <= Xc * Xc + Yc * Yc)
								{
									angle = j - 180;
									break;
								}
							}
						}
					}
					// 90 to 180 degrees
					else if (gTpInfo.x[0] >= gRingSld_Info[i].xR - gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R && gTpInfo.x[0] <= gRingSld_Info[i].xR && gTpInfo.y[0] >= gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R && gTpInfo.y[0] <= gRingSld_Info[i].yR)
					{
						if (gTpInfo.x[0] == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(0)) ||
							gTpInfo.x[0] + 1 == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(0)))
						{
							angle = 180;
						}
						else if (gTpInfo.y[0] == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(270)) ||
								 gTpInfo.y[0] + 1 == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(270)))
						{
							angle = 90;
						}
						else
						{
							for (j = 271; j < 360; j++)
							{
								Xa = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j - 1));
								Ya = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j - 1));
								Xb = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j));
								Yb = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j));
								Xc = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j + 1));
								Yc = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j + 1));
								if (Xb * Xb + Yb * Yb <= Xa * Xa + Ya * Ya && Xb * Xb + Yb * Yb <= Xc * Xc + Yc * Yc)
								{
									angle = j - 180;
									break;
								}
							}
						}
					}

					if (angle <= gRingSld_Info[i].Eangle && angle >= gRingSld_Info[i].Sangle)
					{

						V = (gRingSld_Info[i].Vmax - gRingSld_Info[i].Vmin) * (angle - gRingSld_Info[i].Sangle) / (gRingSld_Info[i].Eangle - gRingSld_Info[i].Sangle) + gRingSld_Info[i].Vmin;

						var[gRingSld_Info[i].p_add * 2] = (V >> 8) & 0xFF;
						var[gRingSld_Info[i].p_add * 2 + 1] = V & 0xFF;

						RingSld_Display(i, angle);

						if (gRingSld_Info[i].p_add >= VAR_ADDR_S)
						{
							reg_operation(gRingSld_Info[i].p_add);
						}
						page_date_update(pic_id);
					}
					else if (angle > gRingSld_Info[i].Eangle && angle < gRingSld_Info[i].Eangle + 10)
					{
						angle = gRingSld_Info[i].Eangle;
						V = (gRingSld_Info[i].Vmax - gRingSld_Info[i].Vmin) * (angle - gRingSld_Info[i].Sangle) / (gRingSld_Info[i].Eangle - gRingSld_Info[i].Sangle) + gRingSld_Info[i].Vmin;

						var[gRingSld_Info[i].p_add * 2] = (V >> 8) & 0xFF;
						var[gRingSld_Info[i].p_add * 2 + 1] = V & 0xFF;

						RingSld_Display(i, angle);

						if (gRingSld_Info[i].p_add >= VAR_ADDR_S)
						{
							reg_operation(gRingSld_Info[i].p_add);
						}
						page_date_update(pic_id);
					}
					else if (angle < gRingSld_Info[i].Sangle && angle + 10 > gRingSld_Info[i].Sangle)
					{
						angle = gRingSld_Info[i].Sangle;
						V = (gRingSld_Info[i].Vmax - gRingSld_Info[i].Vmin) * (angle - gRingSld_Info[i].Sangle) / (gRingSld_Info[i].Eangle - gRingSld_Info[i].Sangle) + gRingSld_Info[i].Vmin;

						var[gRingSld_Info[i].p_add * 2] = (V >> 8) & 0xFF;
						var[gRingSld_Info[i].p_add * 2 + 1] = V & 0xFF;

						RingSld_Display(i, angle);

						if (gRingSld_Info[i].p_add >= VAR_ADDR_S)
						{
							reg_operation(gRingSld_Info[i].p_add);
						}
						page_date_update(pic_id);
					}
				}
			}
		}
	}

	else if (RingSld_firsttouch == 1)
	{
		RingSld_firsttouch = 0;
		button_Press_flag = 0;
		if (gRingSld_Info[RingSld_firstnum].Code == 0xC007)
		{
			rebuf[3] = 0x41;
			rebuf[4] = gRingSld_Info[RingSld_firstnum].p_add >> 8;
			rebuf[5] = gRingSld_Info[RingSld_firstnum].p_add & 0xFF;
			rebuf[6] = var[gRingSld_Info[RingSld_firstnum].p_add * 2];
			rebuf[7] = var[gRingSld_Info[RingSld_firstnum].p_add * 2 + 1];
			LT_SendData_CRC_Frame(rebuf, 5);
		}
	}
}

SldMenu_Info gSldMenu_Info[SLDMENU_SIZE];
uint8_t SLDMfirsttouch = 0;
uint16_t lastx = 0;
uint16_t lasty = 0;
uint16_t Sldw = 0, Sldh = 0;
uint8_t sldmenu_count = 0;
uint8_t sldmenu_num = 0;
uint8_t sldmenu_flag = 0;
uint8_t sld_mum = 0;
uint8_t V_dev = 0;
/***********************************************************************************
 * Function Name : slideMune
 * Description   : Touch detection of slding menu.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void slideMune(void)
{
	uint8_t i = 0;
	uint8_t rebuf[20];
	uint16_t temp, sum, V;
	uint16_t dev = 0;
	int16_t df = 0;

	// press down
	if (gTpInfo.sta)
	{
		for (i = 0; i < sldmenu_count; i++)
		{

			if ((gTpInfo.x[0] >= gSldMenu_Info[i].Xs && gTpInfo.y[0] >= gSldMenu_Info[i].Ys && 
				gTpInfo.x[0] <= gSldMenu_Info[i].Xe && gTpInfo.y[0] <= gSldMenu_Info[i].Ye &&
				button_Press_flag == 0) || sldmenu_flag == 1)
			{

				if (SLDMfirsttouch == 0) // First press
				{
					DL_menu(i);
					SLDMfirsttouch = 1;
					lastx = gTpInfo.x[0];
					lasty = gTpInfo.y[0];
					sldmenu_num = i;
					sldmenu_flag = 1;
					button_Press_flag = 1;
					if (buzzer)
						touch_buzzer();
					V_dev = 0;
				}
				else // Sliding treatment
				{
					if ((gSldMenu_Info[sldmenu_num].dir & 0x01) == 0) // up and down
					{
						df = lasty - gTpInfo.y[0];
						gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos + df;

						if (gSldMenu_Info[sldmenu_num].p_add == (VAR_TIME + 2)) // day is special
						{
							if (var[(VAR_TIME + 1) * 2 + 1] == 1 || var[(VAR_TIME + 1) * 2 + 1] == 3 || var[(VAR_TIME + 1) * 2 + 1] == 5 ||
								var[(VAR_TIME + 1) * 2 + 1] == 7 || var[(VAR_TIME + 1) * 2 + 1] == 8 || var[(VAR_TIME + 1) * 2 + 1] == 10 ||
								var[(VAR_TIME + 1) * 2 + 1] == 12)
							{
								if (gSldMenu_Info[sldmenu_num].V_max > 31)
									dev = (gSldMenu_Info[sldmenu_num].V_max - 31) * (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
								V_dev = 0;
							}
							else if (var[(VAR_TIME + 1) * 2 + 1] == 4 || var[(VAR_TIME + 1) * 2 + 1] == 6 || var[(VAR_TIME + 1) * 2 + 1] == 9 ||
								var[(VAR_TIME + 1) * 2 + 1] == 11)
							{
								if (gSldMenu_Info[sldmenu_num].V_max > 30)
									dev = (gSldMenu_Info[sldmenu_num].V_max - 30) * (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
								V_dev = 1;
							}
							else if (var[(VAR_TIME + 1) * 2 + 1] == 2)
							{
//								if (Is_Leap_Year(var[(VAR_TIME + 0) * 2 + 1] + 2000)) // leap year
//								{
//									if (gSldMenu_Info[sldmenu_num].V_max > 29)
//										dev = (gSldMenu_Info[sldmenu_num].V_max - 29) * (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
//									V_dev = 2;
//								}
//								else
//								{
//									if (gSldMenu_Info[sldmenu_num].V_max > 28)
//										dev = (gSldMenu_Info[sldmenu_num].V_max - 28) * (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
//									V_dev = 3;
//								}
							}
						}

						if (gSldMenu_Info[sldmenu_num].dir == 0x80)
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = 0;
							if (gSldMenu_Info[sldmenu_num].pos > (Sldh - dev - (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2)))
								gSldMenu_Info[sldmenu_num].pos = Sldh - dev - (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						}
						else
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = Sldh - dev + gSldMenu_Info[sldmenu_num].pos;
							if (gSldMenu_Info[sldmenu_num].pos > (Sldh - dev))
								gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos - (Sldh - dev);
						}
						if (df != 0)
						{
							dp_menu(sldmenu_num);
							lasty = gTpInfo.y[0];
						}
					}
					else if ((gSldMenu_Info[sldmenu_num].dir & 0x01) == 1) // the left and right
					{
						df = lastx - gTpInfo.x[0];
						gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos + df;

						if (gSldMenu_Info[sldmenu_num].dir == 0x81)
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = 0; // in range
							if (gSldMenu_Info[sldmenu_num].pos > (Sldw - dev - (gSldMenu_Info[sldmenu_num].Xe - gSldMenu_Info[sldmenu_num].Xs - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2)))
								gSldMenu_Info[sldmenu_num].pos = Sldw - dev - (gSldMenu_Info[sldmenu_num].Xe - gSldMenu_Info[sldmenu_num].Xs - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						}
						else
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = Sldw - dev + gSldMenu_Info[sldmenu_num].pos; // in range
							if (gSldMenu_Info[sldmenu_num].pos > (Sldw - dev))
								gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos - (Sldw - dev);
						}
						if (df != 0)
						{
							dp_menu(sldmenu_num);
							lastx = gTpInfo.x[0];
						}
					}
				}
			}
		}
	} 
	// raise
	else if (sldmenu_flag == 1 && (gTpInfo.sta == 0 ||
								   !(gTpInfo.x[0] >= gSldMenu_Info[sldmenu_num].Xs && gTpInfo.y[0] >= gSldMenu_Info[sldmenu_num].Ys &&
									 gTpInfo.x[0] <= gSldMenu_Info[sldmenu_num].Xe && gTpInfo.y[0] <= gSldMenu_Info[sldmenu_num].Ye))) // ����
	{
		SLDMfirsttouch = 0;
		if ((gSldMenu_Info[sldmenu_num].dir & 0x01) == 0) // up and down
			temp = gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L2 - gSldMenu_Info[sldmenu_num].L1;
		else // left and right
			temp = gSldMenu_Info[sldmenu_num].Xe - gSldMenu_Info[sldmenu_num].Xs - gSldMenu_Info[sldmenu_num].L2 - gSldMenu_Info[sldmenu_num].L1;

		if ((gSldMenu_Info[sldmenu_num].pos % temp) > (temp / 2))
		{
			V = (gSldMenu_Info[sldmenu_num].pos / temp + 1) * gSldMenu_Info[sldmenu_num].step + gSldMenu_Info[sldmenu_num].V_min;
			gSldMenu_Info[sldmenu_num].pos = (V - gSldMenu_Info[sldmenu_num].V_min) / gSldMenu_Info[sldmenu_num].step * temp;
			if (V > gSldMenu_Info[sldmenu_num].V_max - V_dev)
				V = gSldMenu_Info[sldmenu_num].V_min;

			var[gSldMenu_Info[sldmenu_num].p_add * 2] = (V >> 8) & 0xFF;
			var[gSldMenu_Info[sldmenu_num].p_add * 2 + 1] = V & 0xFF;
		}
		else
		{
			V = (gSldMenu_Info[sldmenu_num].pos / temp) * gSldMenu_Info[sldmenu_num].step + gSldMenu_Info[sldmenu_num].V_min;
			gSldMenu_Info[sldmenu_num].pos = (V - gSldMenu_Info[sldmenu_num].V_min) / gSldMenu_Info[sldmenu_num].step * temp;
			if (V > gSldMenu_Info[sldmenu_num].V_max - V_dev)
				V = gSldMenu_Info[sldmenu_num].V_min;

			var[gSldMenu_Info[sldmenu_num].p_add * 2] = (V >> 8) & 0xFF;
			var[gSldMenu_Info[sldmenu_num].p_add * 2 + 1] = V & 0xFF;
		}
		if (gSldMenu_Info[sldmenu_num].Code == 0xC006)
		{
			rebuf[3] = 0x41;
			rebuf[4] = gSldMenu_Info[sldmenu_num].p_add >> 8;
			rebuf[5] = gSldMenu_Info[sldmenu_num].p_add & 0xFF;
			rebuf[6] = var[gSldMenu_Info[sldmenu_num].p_add * 2];
			rebuf[7] = var[gSldMenu_Info[sldmenu_num].p_add * 2 + 1];
			LT_SendData_CRC_Frame(rebuf, 5);
		}
		dp_menu(sldmenu_num);
		if (gSldMenu_Info[sldmenu_num].p_add >= VAR_ADDR_S)
			reg_operation(gSldMenu_Info[sldmenu_num].p_add);

		page_date_update(pic_id);
		sldmenu_flag = 0;
		button_Press_flag = 0;
	}

}

/***********************************************************************************
 * Function Name : dp_menu
 * Description   : Display menu.
 * Input         : - num: which number of sliding menu
 * Output        : None
 * Return        : None
 ************************************************************************************/
void dp_menu(uint8_t num)
{
	uint8_t buff[12] = {0};
	uint16_t box_w, box_h, box_mw, box_mh;

	LT_ReadFlash(buff, addr_index[10] + 12 * gSldMenu_Info[num].frontID, 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	Sldw = buff[4] + (buff[5] << 8);
	Sldh = buff[6] + (buff[7] << 8);
	PICINFO[1].h = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

	PICINFO[1].addr = pic_add;
	PICINFO[1].w = Sldw;
	PICINFO[1].h = Sldh;
	PICINFO[1].len = pic_len;
	PICINFO[1].flag = pic_flag;

	LT_ReadFlash(buff, addr_index[10] + 12 * gSldMenu_Info[num].bgID, 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	Sldw = buff[4] + (buff[5] << 8);
	Sldh = buff[6] + (buff[7] << 8);
	PICINFO[0].h = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

	PICINFO[0].addr = pic_add;
	PICINFO[0].w = Sldw;
	PICINFO[0].h = Sldh;
	PICINFO[0].len = pic_len;
	PICINFO[0].flag = pic_flag;
	

	if ((gSldMenu_Info[num].dir & 0x01) == 0) // up and down
	{
		if (gSldMenu_Info[num].pos > Sldh)
			gSldMenu_Info[num].pos = Sldh;

		box_h = gSldMenu_Info[num].Ye - gSldMenu_Info[num].Ys;
		box_mh = box_h - gSldMenu_Info[num].L1 - gSldMenu_Info[num].L2;

		if (gSldMenu_Info[num].pos == 0 || gSldMenu_Info[num].pos == Sldh)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
					LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
										PICINFO[0].w, box_h, 0);

				LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									0, Sldh - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2, PICINFO[0].w, m_PngData,
									0, box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1, PICINFO[1].w, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < gSldMenu_Info[num].L1)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
					LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
										PICINFO[0].w, box_h, 0);

				LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									0, Sldh - (gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos), PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, PICINFO[0].flag);
				LT268_pic_to_buffer(0, gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, PICINFO[0].w, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].pos, PICINFO[0].flag);

				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1, PICINFO[1].w, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldh - (box_h - gSldMenu_Info[num].L1))) // In the middle
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
					LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
										PICINFO[0].w, box_h, 0);

				LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1, PICINFO[1].w, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldh - box_mh))
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
					LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
										PICINFO[0].w, box_h, 0);

				LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, Sldh - (gSldMenu_Info[num].pos + box_mh), PICINFO[0].flag);
				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2 + Sldh - (gSldMenu_Info[num].pos + box_mh), PICINFO[0].w, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2 - (Sldh - (gSldMenu_Info[num].pos + box_mh)), PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1, PICINFO[1].w, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < Sldh)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
					LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
										PICINFO[0].w, box_h, 0);

				LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh - Sldh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1, PICINFO[1].w, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, Sldh - gSldMenu_Info[num].pos, PICINFO[1].flag);
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1 + Sldh - gSldMenu_Info[num].pos, PICINFO[1].w, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh - (Sldh - gSldMenu_Info[num].pos), PICINFO[1].flag);
				}
			}
		}

		// display
		LT268_buffer_to_TFT(0, 0, PICINFO[0].w, m_PngData,
							gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
	}
	else if ((gSldMenu_Info[num].dir & 0x01) == 1) // the left and right sides
	{
		if (gSldMenu_Info[num].pos > Sldw)
			gSldMenu_Info[num].pos = Sldw;

		box_w = gSldMenu_Info[num].Xe - gSldMenu_Info[num].Xs;
		box_h = gSldMenu_Info[num].Ye - gSldMenu_Info[num].Ys;
		box_mw = box_w - gSldMenu_Info[num].L1 - gSldMenu_Info[num].L2;

		if (gSldMenu_Info[num].pos == 0 || gSldMenu_Info[num].pos == Sldw)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
					LT268_pic_to_buffer(0, 0, box_w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
										box_w, box_h, 0);

				LT268_pic_to_buffer(0, 0, box_w, m_PngData,
									Sldw - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2, 0, box_w, m_PngData,
									box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(gSldMenu_Info[num].L1, 0, box_w, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < gSldMenu_Info[num].L1)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
					LT268_pic_to_buffer(0, 0, box_w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
										box_w, box_h, 0);

				LT268_pic_to_buffer(0, 0, box_w, m_PngData,
									Sldh - (gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos), 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, box_h, PICINFO[0].flag);
				LT268_pic_to_buffer(gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, 0, box_w, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].pos, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos + box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(gSldMenu_Info[num].L1, 0, box_w, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldw - (box_w - gSldMenu_Info[num].L1))) // In the middle
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
					LT268_pic_to_buffer(0, 0, box_w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
										box_w, box_h, 0);

				LT268_pic_to_buffer(0, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos + box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(gSldMenu_Info[num].L1, 0, box_w, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldw - box_mw))
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
					LT268_pic_to_buffer(0, 0, box_w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
										box_w, box_h, 0);

				LT268_pic_to_buffer(0, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos + box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									Sldw - (gSldMenu_Info[num].pos + box_mw), box_h, PICINFO[0].flag);
				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2 + Sldw - (gSldMenu_Info[num].pos + box_mw), 0, box_w, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2 - (Sldw - (gSldMenu_Info[num].pos + box_mw)), box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(gSldMenu_Info[num].L1, 0, box_w, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < Sldw)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
					LT268_pic_to_buffer(0, 0, box_w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
										box_w, box_h, 0);

				LT268_pic_to_buffer(0, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos + box_mw - Sldw, PICINFO[0].w, 0, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(gSldMenu_Info[num].L1, 0, box_w, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										Sldw - gSldMenu_Info[num].pos, box_h, PICINFO[1].flag);
					LT268_pic_to_buffer(gSldMenu_Info[num].L1 + Sldw - gSldMenu_Info[num].pos, 0, box_w, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw - (Sldw - gSldMenu_Info[num].pos), box_h, PICINFO[1].flag);
				}
			}
		}
	}
}

/***********************************************************************************
 * Function Name : DL_menu
 * Description   : Get info of sliding menu.
 * Input         : - num: which number of sliding menu
 * Output        : None
 * Return        : None
 ************************************************************************************/
void DL_menu(uint8_t num)
{
	uint8_t buff[12] = {0};

	LT_ReadFlash(buff, addr_index[10] + 12 * gSldMenu_Info[num].frontID, 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	Sldw = buff[4] + (buff[5] << 8);
	Sldh = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

	gSldMenu_Info[num].flag = pic_flag;

	LT_ReadFlash(buff, addr_index[10] + 12 * gSldMenu_Info[num].bgID, 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	Sldw = buff[4] + (buff[5] << 8);
	Sldh = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];
}

uint8_t CoordinateChangeToBox(uint16_t *x, uint16_t *y, uint16_t *w, uint16_t *h, _PICINFO pic, uint8_t alignment)
{

	if (alignment == 0)
	{
		if (*x < pic.x)
			*x = pic.x;
		if (*x + *w > pic.x + pic.w)
			*w = pic.x + pic.w - *x;
		if (*y < pic.y)
			*y = pic.y;
		if (*y + *h > pic.y + pic.h)
			*h = pic.y + pic.h - *y;
	}
	else if (alignment == 2)
	{
	}

	return 0;
}

/***********************************************************************************
 * Function Name : input_display
 * Description   : Display ASCII data on screen.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void input_display(void)
{
	uint16_t x, y;
	uint32_t zk_addr, fcolor;
	uint8_t font_w, font_h, Alignment;
	uint8_t buff1[4];
	uint16_t box_x, box_y, box_w, box_h;

	LT_ReadFlash(buff1, addr_index[2] + gDio_Info[Dio_num].zk_id * 8, 4);
	zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
	font_w = gDio_Info[Dio_num].zk_w;
	font_h = gDio_Info[Dio_num].zk_h; 

	fcolor = gDio_Info[Dio_num].fcolor;
	Alignment = gDio_Info[Dio_num].Alig;

	box_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x;
	box_y = gDio_Info[Dio_num].dp_y + gDio_Info[Dio_num].kb_y;

	if (Alignment == 0)
	{
		box_w = PICINFO[0].w - gDio_Info[Dio_num].dp_x - 1;
	}
	else if (Alignment == 2)
	{
		box_w = gDio_Info[Dio_num].dp_x - 1;
	}
	box_h = gDio_Info[Dio_num].zk_h;

	// debug
//		printf(" Alignment  %d , font_w font_h  %d  %d  \r\n",Alignment,font_w,font_h);
//		printf(" PICINFO   %d  %d  %d\r\n",PICINFO[0].x,gDio_Info[Dio_num].dp_x,PICINFO[0].w);
//		printf(" xy  %d %d   box_w,box_h %d %d  \r\n",x,y,box_w,box_h);

	LT_Print_zk_Font(4, zk_addr,
					 LAY_BUFF1, LCD_XSIZE_TFT, font_w, font_h, Alignment, fcolor, Black, 0, 1, PICINFO[0], 0,
					 box_x, box_y, box_x + box_w - 1, box_y + box_h - 1,
					 0, 0, Display_buff, sizeof(Display_buff));
	input_w = data_w;
}

uint8_t buff_to_var(uint8_t *buff)
{
	uint8_t i = 0;

	int64_t sum = 0;

	if (neg_flag == 0) // positive number
	{
		for (i = 0; i < i_len; i++)
		{
			sum += pow(10, i_len - 1 - i + gDio_Info[Dio_num].D_num) * (buff[i] - '0');
		}
		for (i = 0; i < d_len; i++)
		{
			sum += pow(10, gDio_Info[Dio_num].D_num - 1 - i) * (buff[i_len + 1 + i] - '0');
		}
	}
	else // negative number
	{
		for (i = 0; i < i_len; i++)
		{
			sum += pow(10, i_len - 1 - i + gDio_Info[Dio_num].D_num) * (buff[i + 1] - '0');
		}
		for (i = 0; i < d_len; i++)
		{
			sum += pow(10, gDio_Info[Dio_num].D_num - 1 - i) * (buff[i_len + 2 + i] - '0');
		}
		sum = sum * (-1);
	}

	if (gDio_Info[Dio_num].Limite_EN == 1)
	{
		// in range
		if (sum >= gDio_Info[Dio_num].V_min && sum <= gDio_Info[Dio_num].V_max)
		{
			if (gDio_Info[Dio_num].p_tpye == 0x00 || gDio_Info[Dio_num].p_tpye == 0x80)
			{
				var[gDio_Info[Dio_num].p_add * 2 + 1] = sum;
			}
			else if (gDio_Info[Dio_num].p_tpye == 0x01 || gDio_Info[Dio_num].p_tpye == 0x81)
			{
				var[gDio_Info[Dio_num].p_add * 2] = sum >> 8 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 1] = sum & 0xFF;
			}
			else if (gDio_Info[Dio_num].p_tpye == 0x02 || gDio_Info[Dio_num].p_tpye == 0x82)
			{
				var[gDio_Info[Dio_num].p_add * 2] = sum >> 24 & 0xFF;
				;
				var[gDio_Info[Dio_num].p_add * 2 + 1] = sum >> 16 & 0xFF;
				;
				var[gDio_Info[Dio_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 3] = sum & 0xFF;
			}
			else if (gDio_Info[Dio_num].p_tpye == 0x83)
			{
				if (sum < 0)
				{
					var[gDio_Info[Dio_num].p_add * 2] = 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 1] = 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 2] = 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 3] = 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 4] = 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 5] = 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 7] = sum & 0xFF;
				}
				else
				{
					var[gDio_Info[Dio_num].p_add * 2] = sum >> 56 & 0xFF;
					;
					var[gDio_Info[Dio_num].p_add * 2 + 1] = sum >> 48 & 0xFF;
					;
					var[gDio_Info[Dio_num].p_add * 2 + 2] = sum >> 40 & 0xFF;
					;
					var[gDio_Info[Dio_num].p_add * 2 + 3] = sum >> 32 & 0xFF;
					;
					var[gDio_Info[Dio_num].p_add * 2 + 4] = sum >> 24 & 0xFF;
					;
					var[gDio_Info[Dio_num].p_add * 2 + 5] = sum >> 16 & 0xFF;
					;
					var[gDio_Info[Dio_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 7] = sum & 0xFF;
				}
			}
			return 0;
		}
		else
			return 1;
	}
	else
	{
		if (gDio_Info[Dio_num].p_tpye == 0x00 || gDio_Info[Dio_num].p_tpye == 0x80)
		{
			var[gDio_Info[Dio_num].p_add * 2 + 1] = sum; // & 0xFF;
		}
		else if (gDio_Info[Dio_num].p_tpye == 0x01 || gDio_Info[Dio_num].p_tpye == 0x81)
		{
			var[gDio_Info[Dio_num].p_add * 2] = sum >> 8 & 0xFF;
			var[gDio_Info[Dio_num].p_add * 2 + 1] = sum & 0xFF;
		}
		else if (gDio_Info[Dio_num].p_tpye == 0x02 || gDio_Info[Dio_num].p_tpye == 0x82)
		{

			var[gDio_Info[Dio_num].p_add * 2] = sum >> 24 & 0xFF;
			;
			var[gDio_Info[Dio_num].p_add * 2 + 1] = sum >> 16 & 0xFF;
			;
			var[gDio_Info[Dio_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
			var[gDio_Info[Dio_num].p_add * 2 + 3] = sum & 0xFF;
		}
		else if (gDio_Info[Dio_num].p_tpye == 0x83)
		{
			if (sum < 0)
			{
				var[gDio_Info[Dio_num].p_add * 2] = 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 1] = 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 2] = 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 3] = 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 4] = 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 5] = 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 7] = sum & 0xFF;
			}
			else
			{
				var[gDio_Info[Dio_num].p_add * 2] = sum >> 56 & 0xFF;
				;
				var[gDio_Info[Dio_num].p_add * 2 + 1] = sum >> 48 & 0xFF;
				;
				var[gDio_Info[Dio_num].p_add * 2 + 2] = sum >> 40 & 0xFF;
				;
				var[gDio_Info[Dio_num].p_add * 2 + 3] = sum >> 32 & 0xFF;
				;
				var[gDio_Info[Dio_num].p_add * 2 + 4] = sum >> 24 & 0xFF;
				;
				var[gDio_Info[Dio_num].p_add * 2 + 5] = sum >> 16 & 0xFF;
				;
				var[gDio_Info[Dio_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 7] = sum & 0xFF;
			}
		}
		return 0;
	}
}

/***********************************************************************************
 * Function Name : data_input
 * Description   : Touch detection of ASCII keyboard.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/

uint8_t PW_pic_flag=0;
uint16_t PW_new1,PW_new2;
void data_input(void)
{
	uint8_t res = 0;
	uint16_t i = 0;
	uint8_t buff[12] = {0};
	uint8_t rebuf[20];
	uint32_t zk_addr = 0;
	uint8_t width_Hor = 0;
	uint32_t color;
	uint8_t PWflag;

	// press down
	if (gTpInfo.sta && DioKb_flag == 0)
	{
		for (i = 0; i < Dio_count; i++)
		{
			if (gTpInfo.x[0] >= gDio_Info[i].Xs && gTpInfo.y[0] >= gDio_Info[i].Ys && gTpInfo.x[0] <= gDio_Info[i].Xe && gTpInfo.y[0] <= gDio_Info[i].Ye && Dio_flag == 0 && button_Press_flag == 0)
			{
					Dio_flag = 1;
					Dio_num = i;			
					button_Press_flag = 1;
					if (buzzer)
						touch_buzzer();							
			}
		}
	}

	// raise
	if (gTpInfo.sta == 0 && Dio_flag == 1 && DioKb_flag == 0)
	{
		if((pic_id==6||(pic_id==5&&Dio_num==0)||(pic_id>=2&&pic_id<=4))&&IO_READ8(Password_Flag_sAddr)==0)	//L第二页密码按键按下但是密码状态是关
		{
			Dio_flag = 0;
			DioKb_flag = 1;
			button_Press_flag = 0;
			Display_page(10);
		}
		else//L增加4色
		{
			if(pic_id==6||(pic_id==5&&Dio_num==0)||(pic_id==7&&Dio_num==0)||(pic_id>=2&&pic_id<=4))
			{
				Password_flag=1;//PW_pic_flag=8;	//菜单按键进入
			}				
			if((pic_id==5&&Dio_num==1)||(pic_id==7&&Dio_num==1))//L后增加红密码页面设置按键ID
			{
//				Password_flag=2;
				if(IO_READ8(Password_Flag_sAddr)==0)	Password_flag=2;	//关密码状态进入
				else Password_flag=3;		//开秘密状态进入
			}
			
			if((pic_id==7&&Dio_num==2))////////////////////////////////////////////////////////增加显示........当前密码-新密码-确认密码
			{
				Password_flag=5;	//if(IO_READ8(Password_Flag_sAddr)==0)	Password_flag=5;	
			}
			
			if (Pop_up_flag == 1) // pop-up window
			{
			}

			LT_ReadFlash(buff, addr_index[6] + 12 * gDio_Info[Dio_num].kb_id, 12);
			PICINFO[0].addr = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			PICINFO[0].w = buff[4] + (buff[5] << 8);
			PICINFO[0].h = buff[6] + (buff[7] << 8);
			PICINFO[0].len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			PICINFO[0].flag = buff[11];
			PICINFO[0].x = gDio_Info[Dio_num].kb_x;
			PICINFO[0].y = gDio_Info[Dio_num].kb_y;
			
			pic_id_temp = pic_id;
			pic_id = gDio_Info[Dio_num].kb_id;
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 0)
					LT268_TFT_ShowPicture(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
				if (PICINFO[0].flag == 1)
					LT268_TFT_ShowPicture_Png(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
				if (PICINFO[0].flag == 2)
					LT268_TFT_ShowPicture_Png_Pixel(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
			}
//			if(PW_pic_flag==1)	LT268_TFT_ShowPicture(95, 9, 130, 35, Xinmima_addr);	//显示新密码
//			if(PW_pic_flag==8)	LT268_TFT_ShowPicture(95, 9, 130, 35, Mima_addr);	//显示密码
			if(Password_flag==2)	//显示 新密码
			{
				if(Language_state==2)
					Display_Icon(1651, MiMa_X, MiMa_Y, 0);
				else if(Language_state==3)
					Display_Icon(1652, MiMa_X, MiMa_Y, 0);
				else if(Language_state==4)
					Display_Icon(1653, MiMa_X, MiMa_Y, 0);
				else if(Language_state==5)
					Display_Icon(1654, MiMa_X, MiMa_Y, 0);
				else if(Language_state==6)
					Display_Icon(1655, MiMa_X, MiMa_Y, 0);
				else if(Language_state==7)
					Display_Icon(1656, MiMa_X, MiMa_Y, 0);
				else if(Language_state==8)
					Display_Icon(1657, MiMa_X, MiMa_Y, 0);
				else if(Language_state==9)
					Display_Icon(1658, MiMa_X, MiMa_Y, 0);
				else if(Language_state==10)
					Display_Icon(1659, MiMa_X, MiMa_Y, 0);
				else if(Language_state==11)
					Display_Icon(1660, MiMa_X, MiMa_Y, 0);
				else if(Language_state==12)
					Display_Icon(1661, MiMa_X, MiMa_Y, 0);
				else
					Display_Icon(1650, MiMa_X, MiMa_Y, 0);				
			}				
			if(Password_flag==1||Password_flag==3)		//显示 密码
			{
				if(Language_state==2)
					Display_Icon(1611, MiMa_X, MiMa_Y, 0);
				else if(Language_state==3)
					Display_Icon(1612, MiMa_X, MiMa_Y, 0);
				else if(Language_state==4)
					Display_Icon(1613, MiMa_X, MiMa_Y, 0);
				else if(Language_state==5)
					Display_Icon(1614, MiMa_X, MiMa_Y, 0);
				else if(Language_state==6)
					Display_Icon(1615, MiMa_X, MiMa_Y, 0);
				else if(Language_state==7)
					Display_Icon(1616, MiMa_X, MiMa_Y, 0);
				else if(Language_state==8)
					Display_Icon(1617, MiMa_X, MiMa_Y, 0);
				else if(Language_state==9)
					Display_Icon(1618, MiMa_X, MiMa_Y, 0);
				else if(Language_state==10)
					Display_Icon(1619, MiMa_X, MiMa_Y, 0);
				else if(Language_state==11)
					Display_Icon(1620, MiMa_X, MiMa_Y, 0);
				else if(Language_state==12)
					Display_Icon(1621, MiMa_X, MiMa_Y, 0);
				else
					Display_Icon(1610, MiMa_X, MiMa_Y, 0);				
			}
			if(Password_flag==5)		// 增加显示      当前密码
			{
				if(Language_state==2)
					Display_Icon(1980, MiMa_X, MiMa_Y, 0);
				else if(Language_state==3)
					Display_Icon(1981, MiMa_X, MiMa_Y, 0);
				else if(Language_state==4)
					Display_Icon(1982, MiMa_X, MiMa_Y, 0);
				else if(Language_state==5)
					Display_Icon(1983, MiMa_X, MiMa_Y, 0);
				else if(Language_state==6)
					Display_Icon(1984, MiMa_X, MiMa_Y, 0);
				else if(Language_state==7)
					Display_Icon(1985, MiMa_X, MiMa_Y, 0);
				else if(Language_state==8)
					Display_Icon(1986, MiMa_X, MiMa_Y, 0);
				else if(Language_state==9)
					Display_Icon(1987, MiMa_X, MiMa_Y, 0);
				else if(Language_state==10)
					Display_Icon(1988, MiMa_X, MiMa_Y, 0);
				else if(Language_state==11)
					Display_Icon(1989, MiMa_X, MiMa_Y, 0);
				else if(Language_state==12)
					Display_Icon(1990, MiMa_X, MiMa_Y, 0);
				else
					Display_Icon(1979, MiMa_X, MiMa_Y, 0);				
			}
			/*Dynamic picture coverage judgment*/
			DioKb_flag = 1;
			gDio_Info[Dio_num].Xs = gDio_Info[Dio_num].kb_x;
			gDio_Info[Dio_num].Ys = gDio_Info[Dio_num].kb_y;
			gDio_Info[Dio_num].Xe = gDio_Info[Dio_num].kb_x + PICINFO[0].w;
			gDio_Info[Dio_num].Ye = gDio_Info[Dio_num].kb_y + PICINFO[0].h;

			LT_ReadFlash(buff, addr_index[2] + gDio_Info[Dio_num].zk_id * 8, 4);
			zk_addr = buff[0] + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);

			LT_ReadFlash(&gDio_Info[Dio_num].zk_h, zk_addr + 3, 1); 


//			if (gDio_Info[Dio_num].cursor_color == 0)
//				color = Black;
//			else
//				color = White;
//			
//	//		cur_w = gDio_Info[Dio_num].zk_w / 2;
//	//		LT_ReadFlash(&cur_w, zk_addr + 9 + 92, 1);
//			cur_w = gDio_Info[Dio_num].zk_w;

//			if (gDio_Info[Dio_num].Alig == 0)
//				cur_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x;
//			else
//				cur_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x - cur_w;
//			cur_y = gDio_Info[Dio_num].dp_y + gDio_Info[Dio_num].kb_y;
//		
//			
//			buff[0] = '|';
//			buff[1] = 0;
//			LT_Print_zk_Font(4, zk_addr,
//							 LAY_BUFF1, LCD_XSIZE_TFT, gDio_Info[Dio_num].zk_w, gDio_Info[Dio_num].zk_h, gDio_Info[Dio_num].Alig, color, Black, 0, 1, PICINFO[0], 0,
//							 cur_x, cur_y, cur_x + cur_w + 1, cur_y + gDio_Info[Dio_num].zk_h -1,
//							 0, 0, buff, 1);  
			
			Get_Touch_info(gDio_Info[Dio_num].kb_id);  //get info
			button_Press_flag = 0;
			Cusor_time = 0;
			Dio_flag = 0;
			i_len = 0;
			d_len = 0;
			input_len = 0;
			neg_flag = 0;
			dot_flag = 0;
			input_w = 0;
			memset(Display_buff, 0, sizeof(Display_buff));			
		}

	}

	// Press down within the range of keyboard
	if (gTpInfo.sta && DioKb_flag == 1 && Dio_flag == 0)
	{
		for (i = 0; i < Kb_count; i++)
		{
			if (gTpInfo.x[0] >= gKb_Info[i].Xs + gDio_Info[Dio_num].kb_x && gTpInfo.y[0] >= gKb_Info[i].Ys + gDio_Info[Dio_num].kb_y && gTpInfo.x[0] <= gKb_Info[i].Xe + gDio_Info[Dio_num].kb_x && gTpInfo.y[0] <= gKb_Info[i].Ye + gDio_Info[Dio_num].kb_y && Kb_flag == 0)
			{
				if (gKb_Info[i].press_id != 0xFFFF)
				{
					LT_ReadFlash(buff, addr_index[6] + 12 * gKb_Info[i].press_id, 12);
					pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
					pic_w = buff[4] + (buff[5] << 8);
					pic_h = buff[6] + (buff[7] << 8);
					pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
					pic_flag = buff[11];

					LT268_dispaly_CutPicture(gDio_Info[Dio_num].kb_x + gKb_Info[i].Xs, gDio_Info[Dio_num].kb_y + gKb_Info[i].Ys,
											 gKb_Info[i].Xs, gKb_Info[i].Ys, gKb_Info[i].Xe - gKb_Info[i].Xs + 1, gKb_Info[i].Ye - gKb_Info[i].Ys + 1,
											 pic_w, pic_add, pic_len, pic_flag);
				}
				Kb_num = i;
				Kb_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}

	// raise
	if (gTpInfo.sta == 0 && DioKb_flag == 1 && Kb_flag == 1)
	{
		LT_ReadFlash(buff, addr_index[6] + 12 * gDio_Info[Dio_num].kb_id, 12);
		PICINFO[0].addr = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		PICINFO[0].w = buff[4] + (buff[5] << 8);
		PICINFO[0].h = buff[6] + (buff[7] << 8);
		PICINFO[0].len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		PICINFO[0].flag = buff[11];
		PICINFO[0].x = gDio_Info[Dio_num].kb_x;
		PICINFO[0].y = gDio_Info[Dio_num].kb_y;

		if (gKb_Info[Kb_num].press_id != 0xFFFF)
		{

			LT268_dispaly_CutPicture(gDio_Info[Dio_num].kb_x + gKb_Info[Kb_num].Xs, gDio_Info[Dio_num].kb_y + gKb_Info[Kb_num].Ys,
									 gKb_Info[Kb_num].Xs, gKb_Info[Kb_num].Ys, gKb_Info[Kb_num].Xe - gKb_Info[Kb_num].Xs + 1, gKb_Info[Kb_num].Ye - gKb_Info[Kb_num].Ys + 1,
									 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);
		}

		if (gKb_Info[Kb_num].Keyvalue == 0x2E && gDio_Info[Dio_num].D_num > 0 && dot_flag == 0) // '.'
		{
			if ((input_len > 0 && neg_flag == 0) || (input_len > 1 && neg_flag == 1))
			{
				Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xff;
				input_len++;
				dot_flag = 1;
				input_display();
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0x2D && neg_flag == 0 && i_len == 0 && d_len == 0) // '-'
		{
			if (gDio_Info[Dio_num].p_tpye == 0x80 || gDio_Info[Dio_num].p_tpye == 0x81 || gDio_Info[Dio_num].p_tpye == 0x82 || gDio_Info[Dio_num].p_tpye == 0x83)
			{
				neg_flag = 1;
				Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xff;
				input_len++;
				input_display();
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF0) // cancel
		{
			DioKb_flag = 0;
			if (Pop_up_flag == 0)
				Display_page(pic_id_temp);
			else if (Pop_up_flag == 1)
			{
				Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF2) // backspace
		{
			if (dot_flag == 1) // with decimal point
			{
				if (d_len > 0)
				{
					d_len--;
				}
				else
					dot_flag = 0;
			}
			else if (i_len > 0)
				i_len--;

			if (input_len > 0)
			{
				input_len--;
				if (input_len == 0 && neg_flag == 1)
					neg_flag = 0;
				Display_buff[input_len] = 0x00;
				input_display();
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF1) // confirm
		{
			res = buff_to_var(Display_buff);
			
			if (res == 0)
			{
				if (gDio_Info[Dio_num].Code == 0xC002)
				{
					rebuf[3] = 0x41;
					rebuf[4] = gDio_Info[Dio_num].p_add >> 8;
					rebuf[5] = gDio_Info[Dio_num].p_add & 0xFF;
					if (gDio_Info[Dio_num].p_tpye == 0x00 || gDio_Info[Dio_num].p_tpye == 0x80)
					{
						rebuf[6] = var[gDio_Info[Dio_num].p_add * 2];
						rebuf[7] = var[gDio_Info[Dio_num].p_add * 2 + 1];
						LT_SendData_CRC_Frame(rebuf, 5);
					}
					else if (gDio_Info[Dio_num].p_tpye == 0x01 || gDio_Info[Dio_num].p_tpye == 0x81)
					{
						rebuf[6] = var[gDio_Info[Dio_num].p_add * 2];
						rebuf[7] = var[gDio_Info[Dio_num].p_add * 2 + 1];
						LT_SendData_CRC_Frame(rebuf, 5);
					}
					else if (gDio_Info[Dio_num].p_tpye == 0x02 || gDio_Info[Dio_num].p_tpye == 0x82)
					{
						rebuf[6] = var[gDio_Info[Dio_num].p_add * 2];
						rebuf[7] = var[gDio_Info[Dio_num].p_add * 2 + 1];
						rebuf[8] = var[gDio_Info[Dio_num].p_add * 2 + 2];
						rebuf[9] = var[gDio_Info[Dio_num].p_add * 2 + 3];
						LT_SendData_CRC_Frame(rebuf, 7);
					}
					else if (gDio_Info[Dio_num].p_tpye == 0x03 || gDio_Info[Dio_num].p_tpye == 0x83)
					{
						rebuf[6] = var[gDio_Info[Dio_num].p_add * 2];
						rebuf[7] = var[gDio_Info[Dio_num].p_add * 2 + 1];
						rebuf[8] = var[gDio_Info[Dio_num].p_add * 2 + 2];
						rebuf[9] = var[gDio_Info[Dio_num].p_add * 2 + 3];
						rebuf[10] = var[gDio_Info[Dio_num].p_add * 2 + 4];
						rebuf[11] = var[gDio_Info[Dio_num].p_add * 2 + 5];
						rebuf[12] = var[gDio_Info[Dio_num].p_add * 2 + 6];
						rebuf[13] = var[gDio_Info[Dio_num].p_add * 2 + 7];
						LT_SendData_CRC_Frame(rebuf, 11);
					}
				}
				DioKb_flag = 0;
				if (Pop_up_flag == 0)
				{
					if(Password_flag==2)	//确认后进入确认密码界面
					{
						PW_new1=(var[0x1810*2]<<8) + var[0x1810*2+1];
						if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
						{
							if (PICINFO[0].flag == 0)
								LT268_TFT_ShowPicture(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
							if (PICINFO[0].flag == 1)
								LT268_TFT_ShowPicture_Png(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
							if (PICINFO[0].flag == 2)
								LT268_TFT_ShowPicture_Png_Pixel(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
						}
						//显示确认密码
						if(Language_state==2)
							Display_Icon(1631, MiMa_X, MiMa_Y, 0);
						else if(Language_state==3)
							Display_Icon(1632, MiMa_X, MiMa_Y, 0);
						else if(Language_state==4)
							Display_Icon(1633, MiMa_X, MiMa_Y, 0);
						else if(Language_state==5)
							Display_Icon(1634, MiMa_X, MiMa_Y, 0);
						else if(Language_state==6)
							Display_Icon(1635, MiMa_X, MiMa_Y, 0);
						else if(Language_state==7)
							Display_Icon(1636, MiMa_X, MiMa_Y, 0);
						else if(Language_state==8)
							Display_Icon(1637, MiMa_X, MiMa_Y, 0);
						else if(Language_state==9)
							Display_Icon(1638, MiMa_X, MiMa_Y, 0);
						else if(Language_state==10)
							Display_Icon(1639, MiMa_X, MiMa_Y, 0);
						else if(Language_state==11)
							Display_Icon(1640, MiMa_X, MiMa_Y, 0);
						else if(Language_state==12)
							Display_Icon(1641, MiMa_X, MiMa_Y, 0);
						else
							Display_Icon(1630, MiMa_X, MiMa_Y, 0);	
						/*Dynamic picture coverage judgment*/
						DioKb_flag = 1;
						gDio_Info[Dio_num].Xs = gDio_Info[Dio_num].kb_x;
						gDio_Info[Dio_num].Ys = gDio_Info[Dio_num].kb_y;
						gDio_Info[Dio_num].Xe = gDio_Info[Dio_num].kb_x + PICINFO[0].w;
						gDio_Info[Dio_num].Ye = gDio_Info[Dio_num].kb_y + PICINFO[0].h;

						LT_ReadFlash(buff, addr_index[2] + gDio_Info[Dio_num].zk_id * 8, 4);
						zk_addr = buff[0] + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
						LT_ReadFlash(&gDio_Info[Dio_num].zk_h, zk_addr + 3, 1); 
						Get_Touch_info(gDio_Info[Dio_num].kb_id);  //get info
						button_Press_flag = 0;
						Cusor_time = 0;
						Dio_flag = 0;
						i_len = 0;
						d_len = 0;
						input_len = 0;
						neg_flag = 0;
						dot_flag = 0;
						input_w = 0;
						memset(Display_buff, 0, sizeof(Display_buff));
						Password_flag=4;
					}
					else if(Password_flag==1||Password_flag==3||Password_flag==4||Password_flag==5)
					{
							uint16_t PWvalue1,PWvalue2;
							PWvalue1 = (var[0x1810*2]<<8) + var[0x1810*2+1];
							PWvalue2 = ((uint32_t)IO_READ8(PasswordH_sAddr)<<8) + IO_READ8(PasswordL_sAddr);
							if((Password_flag==1||Password_flag==3)&&PWvalue1==PWvalue2)
							{
								if(Password_flag==1)//正确
								{
								Display_page(36);
								DelayMS(1000);		
								Display_page(10);
								//printf("-----------correct------\r\n");
								}
								else if(Password_flag==3)
								{
									EFLASH_Init(g_sys_clk / 1000);
									EFLASH_SetWritePermission();
									W_buff[13] = 0;	//关闭密码
									EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
									EFLASH_ClrWritePermission();
									Display_page(5);								
								}
								Password_flag=0;
							}
							else if(Password_flag==4&&PW_new1==PWvalue1)	
							{		
								W_buff[13] = 1;								
								W_buff[14] = var[0x1810*2];
								W_buff[15] = var[0x1810*2+1];

								EFLASH_Init(g_sys_clk / 1000);
								EFLASH_SetWritePermission();								
								EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
								EFLASH_ClrWritePermission();
								
								LT268_TFT_FillColor(0, 0, LCD_XSIZE_TFT, LCD_YSIZE_TFT, Black);
								//显示密码设置成功
  								if(Language_state>0)
							    Display_page(36);
								DelayMS(2000);								
								Display_page(pic_id_temp);	
								Password_flag=0;
								//printf("-----------12121212121212------\r\n");
								Display_page(7);								
							}		
							else if(Password_flag==5&&PWvalue1==PWvalue2)	
							{		
								if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
								{
									if (PICINFO[0].flag == 0)
										LT268_TFT_ShowPicture(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
									if (PICINFO[0].flag == 1)
										LT268_TFT_ShowPicture_Png(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
									if (PICINFO[0].flag == 2)
										LT268_TFT_ShowPicture_Png_Pixel(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
								}
								//显示新密码
								if(Language_state==2)
									Display_Icon(1651, MiMa_X, MiMa_Y, 0);
								else if(Language_state==3)
									Display_Icon(1652, MiMa_X, MiMa_Y, 0);
								else if(Language_state==4)
									Display_Icon(1653, MiMa_X, MiMa_Y, 0);
								else if(Language_state==5)
									Display_Icon(1654, MiMa_X, MiMa_Y, 0);
								else if(Language_state==6)
									Display_Icon(1655, MiMa_X, MiMa_Y, 0);
								else if(Language_state==7)
									Display_Icon(1656, MiMa_X, MiMa_Y, 0);
								else if(Language_state==8)
									Display_Icon(1657, MiMa_X, MiMa_Y, 0);
								else if(Language_state==9)
									Display_Icon(1658, MiMa_X, MiMa_Y, 0);
								else if(Language_state==10)
									Display_Icon(1659, MiMa_X, MiMa_Y, 0);
								else if(Language_state==11)
									Display_Icon(1660, MiMa_X, MiMa_Y, 0);
								else if(Language_state==12)
									Display_Icon(1661, MiMa_X, MiMa_Y, 0);
								else
									Display_Icon(1650, MiMa_X, MiMa_Y, 0);	
								/*Dynamic picture coverage judgment*/
								DioKb_flag = 1;
								gDio_Info[Dio_num].Xs = gDio_Info[Dio_num].kb_x;
								gDio_Info[Dio_num].Ys = gDio_Info[Dio_num].kb_y;
								gDio_Info[Dio_num].Xe = gDio_Info[Dio_num].kb_x + PICINFO[0].w;
								gDio_Info[Dio_num].Ye = gDio_Info[Dio_num].kb_y + PICINFO[0].h;

								LT_ReadFlash(buff, addr_index[2] + gDio_Info[Dio_num].zk_id * 8, 4);
								zk_addr = buff[0] + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);

								LT_ReadFlash(&gDio_Info[Dio_num].zk_h, zk_addr + 3, 1); 


								if (gDio_Info[Dio_num].cursor_color == 0)
									color = Black;
								else
									color = White;
								
								cur_w = gDio_Info[Dio_num].zk_w;

								if (gDio_Info[Dio_num].Alig == 0)
									cur_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x;
								else
									cur_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x - cur_w;
								cur_y = gDio_Info[Dio_num].dp_y + gDio_Info[Dio_num].kb_y;
							
								
								buff[0] = '|';
								buff[1] = 0;
								
								LT_Print_zk_Font(4, zk_addr,
												 LAY_BUFF1, LCD_XSIZE_TFT, gDio_Info[Dio_num].zk_w, gDio_Info[Dio_num].zk_h, gDio_Info[Dio_num].Alig, color, Black, 0, 1, PICINFO[0], 0,
												 cur_x, cur_y, cur_x + cur_w + 1, cur_y + gDio_Info[Dio_num].zk_h -1,
												 0, 0, buff, 1);  
								
								Get_Touch_info(gDio_Info[Dio_num].kb_id);  //get info
								button_Press_flag = 0;
								Cusor_time = 0;
								Dio_flag = 0;
								i_len = 0;
								d_len = 0;
								input_len = 0;
								neg_flag = 0;
								dot_flag = 0;
								input_w = 0;
								memset(Display_buff, 0, sizeof(Display_buff));
								Password_flag=2;
								
							}							
							else	//密码错误	
							{
								//LT268_TFT_FillColor(0, 0, LCD_XSIZE_TFT, LCD_YSIZE_TFT, Black);
								//显示密码错误
								if(Language_state>0)
								Display_page(37);
								DelayMS(2000);
								if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
								{
									if (PICINFO[0].flag == 0)
										LT268_TFT_ShowPicture(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
									if (PICINFO[0].flag == 1)
										LT268_TFT_ShowPicture_Png(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
									if (PICINFO[0].flag == 2)
										LT268_TFT_ShowPicture_Png_Pixel(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
								}
								if(Password_flag==1||Password_flag==3)	//显示密码
								{
									if(Language_state==2)
										Display_Icon(1611, MiMa_X, MiMa_Y, 0);
									else if(Language_state==3)
										Display_Icon(1612, MiMa_X, MiMa_Y, 0);
									else if(Language_state==4)
										Display_Icon(1613, MiMa_X, MiMa_Y, 0);
									else if(Language_state==5)
										Display_Icon(1614, MiMa_X, MiMa_Y, 0);
									else if(Language_state==6)
										Display_Icon(1615, MiMa_X, MiMa_Y, 0);
									else if(Language_state==7)
										Display_Icon(1616, MiMa_X, MiMa_Y, 0);
									else if(Language_state==8)
										Display_Icon(1617, MiMa_X, MiMa_Y, 0);
									else if(Language_state==9)
										Display_Icon(1618, MiMa_X, MiMa_Y, 0);
									else if(Language_state==10)
										Display_Icon(1619, MiMa_X, MiMa_Y, 0);
									else if(Language_state==11)
										Display_Icon(1620, MiMa_X, MiMa_Y, 0);
									else if(Language_state==12)
										Display_Icon(1621, MiMa_X, MiMa_Y, 0);
									else
										Display_Icon(1610, MiMa_X, MiMa_Y, 0);									
								}
								else if(Password_flag==4)
								{
									if(Language_state==2)			//显示新密码
										Display_Icon(1651, MiMa_X, MiMa_Y, 0);
									else if(Language_state==3)
										Display_Icon(1652, MiMa_X, MiMa_Y, 0);
									else if(Language_state==4)
										Display_Icon(1653, MiMa_X, MiMa_Y, 0);
									else if(Language_state==5)
										Display_Icon(1654, MiMa_X, MiMa_Y, 0);
									else if(Language_state==6)
										Display_Icon(1655, MiMa_X, MiMa_Y, 0);
									else if(Language_state==7)
										Display_Icon(1656, MiMa_X, MiMa_Y, 0);
									else if(Language_state==8)
										Display_Icon(1657, MiMa_X, MiMa_Y, 0);
									else if(Language_state==9)
										Display_Icon(1658, MiMa_X, MiMa_Y, 0);
									else if(Language_state==10)
										Display_Icon(1659, MiMa_X, MiMa_Y, 0);
									else if(Language_state==11)
										Display_Icon(1660, MiMa_X, MiMa_Y, 0);
									else if(Language_state==12)
										Display_Icon(1661, MiMa_X, MiMa_Y, 0);
									else
										Display_Icon(1650, MiMa_X, MiMa_Y, 0);
									Password_flag=2;
								}
								else if(Password_flag==5)			//显示当前密码
								{
									if(Language_state==2)
										Display_Icon(1980, MiMa_X, MiMa_Y, 0);
									else if(Language_state==3)
										Display_Icon(1981, MiMa_X, MiMa_Y, 0);
									else if(Language_state==4)
										Display_Icon(1982, MiMa_X, MiMa_Y, 0);
									else if(Language_state==5)
										Display_Icon(1983, MiMa_X, MiMa_Y, 0);
									else if(Language_state==6)
										Display_Icon(1984, MiMa_X, MiMa_Y, 0);
									else if(Language_state==7)
										Display_Icon(1985, MiMa_X, MiMa_Y, 0);
									else if(Language_state==8)
										Display_Icon(1986, MiMa_X, MiMa_Y, 0);
									else if(Language_state==9)
										Display_Icon(1987, MiMa_X, MiMa_Y, 0);
									else if(Language_state==10)
										Display_Icon(1988, MiMa_X, MiMa_Y, 0);
									else if(Language_state==11)
										Display_Icon(1989, MiMa_X, MiMa_Y, 0);
									else if(Language_state==12)
										Display_Icon(1990, MiMa_X, MiMa_Y, 0);
									else
										Display_Icon(1979, MiMa_X, MiMa_Y, 0);		
									//Password_flag=2;
								}
								/*Dynamic picture coverage judgment*/
								DioKb_flag = 1;
								gDio_Info[Dio_num].Xs = gDio_Info[Dio_num].kb_x;
								gDio_Info[Dio_num].Ys = gDio_Info[Dio_num].kb_y;
								gDio_Info[Dio_num].Xe = gDio_Info[Dio_num].kb_x + PICINFO[0].w;
								gDio_Info[Dio_num].Ye = gDio_Info[Dio_num].kb_y + PICINFO[0].h;

								LT_ReadFlash(buff, addr_index[2] + gDio_Info[Dio_num].zk_id * 8, 4);
								zk_addr = buff[0] + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);

								LT_ReadFlash(&gDio_Info[Dio_num].zk_h, zk_addr + 3, 1); 


//								if (gDio_Info[Dio_num].cursor_color == 0)
//									color = Black;
//								else
//									color = White;
//								
//						//		cur_w = gDio_Info[Dio_num].zk_w / 2;
//						//		LT_ReadFlash(&cur_w, zk_addr + 9 + 92, 1);
//								cur_w = gDio_Info[Dio_num].zk_w;

//								if (gDio_Info[Dio_num].Alig == 0)
//									cur_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x;
//								else
//									cur_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x - cur_w;
//								cur_y = gDio_Info[Dio_num].dp_y + gDio_Info[Dio_num].kb_y;
//							
//								
//								buff[0] = '|';
//								buff[1] = 0;
//								
//								LT_Print_zk_Font(4, zk_addr,
//												 LAY_BUFF1, LCD_XSIZE_TFT, gDio_Info[Dio_num].zk_w, gDio_Info[Dio_num].zk_h, gDio_Info[Dio_num].Alig, color, Black, 0, 1, PICINFO[0], 0,
//												 cur_x, cur_y, cur_x + cur_w + 1, cur_y + gDio_Info[Dio_num].zk_h -1,
//												 0, 0, buff, 1);  
								
								Get_Touch_info(gDio_Info[Dio_num].kb_id);  //get info
								button_Press_flag = 0;
								Cusor_time = 0;
								Dio_flag = 0;
								i_len = 0;
								d_len = 0;
								input_len = 0;
								neg_flag = 0;
								dot_flag = 0;
								input_w = 0;
								memset(Display_buff, 0, sizeof(Display_buff));
//								Display_page(9);					
							}					
//						}
//						else 
//						{
//							Display_page(pic_id_temp);		
//							Password_flag=0;
//						}
												
					}

				}
				else if (Pop_up_flag == 1)
				{
					Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
				}
			}
			
		}
		else if (gKb_Info[Kb_num].Keyvalue >= '0' && gKb_Info[Kb_num].Keyvalue <= '9') // Digital input
		{
			if ((i_len < gDio_Info[Dio_num].I_num && dot_flag == 0) || (d_len < gDio_Info[Dio_num].D_num && dot_flag == 1))
			{
				Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xff;
				if (dot_flag == 0)
					i_len++; // Integer length plus
				else
					d_len++; // Decimal length plus
				input_len++; // Display buff length plus

				input_display();
			}
		}
		Kb_flag = 0;
	}
}

/***********************************************************************************
 * Function Name : Ascii_input
 * Description   : Touch detection of ASCII keyboard.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Ascii_input(void)
{
	uint8_t res = 0;
	uint16_t i = 0;
	uint8_t rebuf[50];
	uint8_t buff1[12] = {0};
	uint16_t k = 0;
	uint32_t zk_addr = 0;
	uint8_t width_Hor = 0;
	uint32_t color;

	// press down
	if (gTpInfo.sta && AioKb_flag == 0)
	{
		for (i = 0; i < Aio_count; i++)
		{
			if (gTpInfo.x[0] >= gAio_Info[i].Xs && gTpInfo.y[0] >= gAio_Info[i].Ys && gTpInfo.x[0] <= gAio_Info[i].Xe && gTpInfo.y[0] <= gAio_Info[i].Ye && Aio_flag == 0 && button_Press_flag == 0)
			{
				button_Press_flag = 1;
				Aio_num = i;
				Aio_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}

	// keep pressing
	if (gTpInfo.sta == 0 && AioKb_flag == 0 && Aio_flag == 1)
	{
		if (Pop_up_flag == 1) // pop-up window
		{
		}

		LT_ReadFlash(buff1, addr_index[6] + 12 * gAio_Info[Aio_num].kb_id, 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		// Record picture information of keyboard
		PICINFO[0].addr = pic_add;
		PICINFO[0].w = pic_w;
		PICINFO[0].h = pic_h;
		PICINFO[0].len = pic_len;
		PICINFO[0].flag = pic_flag;
		PICINFO[0].x = gAio_Info[Aio_num].kb_x;
		PICINFO[0].y = gAio_Info[Aio_num].kb_y;

		/*Dynamic picture coverage judgment*/
		AioKb_flag = 1;
		gAio_Info[Aio_num].Xs = gAio_Info[Aio_num].kb_x;
		gAio_Info[Aio_num].Ys = gAio_Info[Aio_num].kb_y;
		gAio_Info[Aio_num].Xe = gAio_Info[Aio_num].kb_x + pic_w;
		gAio_Info[Aio_num].Ye = gAio_Info[Aio_num].kb_y + pic_h;

		LT_ReadFlash(buff1, addr_index[2] + gAio_Info[Aio_num].zk_id * 8, 4);
		gAio_Info[Aio_num].zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		
		cur_x = gAio_Info[Aio_num].dp_x + gAio_Info[Aio_num].kb_x;
		cur_y = gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y;
		buff1[0] = '|';
		buff1[1] = 0;

		if (gAio_Info[Aio_num].cursor_color == 0)
			color = Black;
		else
			color = White;

//		cur_w = gAio_Info[Aio_num].zk_w / 2;
		cur_w = gAio_Info[Aio_num].zk_w;

		Get_Touch_info(gAio_Info[Aio_num].kb_id);
		Aio_flag = 0;
		button_Press_flag = 0;
		input_len = 0;
		CapsLock = 0;
		input_w = 0;
		memset(Display_buff, 0, sizeof(Display_buff));
		
		pic_id_temp = pic_id;
		pic_id = gAio_Info[Aio_num].kb_id;

		if (gAio_Info[Aio_num].scan_mode == 1)
		{
			for (k = 0; k < gAio_Info[Aio_num].p_len * 2; k++)
			{
				if (var[gAio_Info[Aio_num].p_add * 2 + k] > 0x7F)
					break;
				Display_buff[k] = var[gAio_Info[Aio_num].p_add * 2 + k];
				if (var[gAio_Info[Aio_num].p_add * 2 + k] == 0x00 && var[gAio_Info[Aio_num].p_add * 2 + k + 1] == 0x00)
					break;
			}

			input_len = k;

			// display keyboard
			if (PICINFO[0].flag == 0)
				LT268_TFT_ShowPicture(gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
			if (PICINFO[0].flag == 1)
				LT268_TFT_ShowPicture_Png(gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
			if (PICINFO[0].flag == 2)
				LT268_TFT_ShowPicture_Png_Pixel(gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);

			// display ASCII data on keyboard
			LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, gAio_Info[Aio_num].fcolor, White, 0, 1, PICINFO[0], gAio_Info[Aio_num].input_mode,
							 gAio_Info[Aio_num].dp_x + gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y,
							 PICINFO[0].x + PICINFO[0].w, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y + gAio_Info[Aio_num].zk_h - 1,
							 0, 0, Display_buff, input_len);
			
			input_w = data_w;
			
			LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
							 cur_x + input_w, cur_y,  cur_x + input_w + cur_w + 1, cur_y + gAio_Info[Aio_num].zk_h - 1,
							  0, 0, buff1, 1);
		}
		else
		{
			if (PICINFO[0].flag == 0)
				LT268_TFT_ShowPicture(gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
			if (PICINFO[0].flag == 1)
				LT268_TFT_ShowPicture_Png(gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
			if (PICINFO[0].flag == 2)
				LT268_TFT_ShowPicture_Png_Pixel(gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
			
			LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
							 cur_x, cur_y,  cur_x + cur_w + 1, cur_y + gAio_Info[Aio_num].zk_h - 1,
							  0, 0, buff1, 1);
		}

		// AioKb_flag = 1;
		Cusor_time = 0;
	}

	// press down within the range of keyboard
	if (gTpInfo.sta && AioKb_flag == 1 && Aio_flag == 0)
	{
		for (i = 0; i < Kb_count; i++)
		{
			if (gTpInfo.x[0] >= gKb_Info[i].Xs + gAio_Info[Aio_num].kb_x && gTpInfo.y[0] >= gKb_Info[i].Ys + gAio_Info[Aio_num].kb_y && gTpInfo.x[0] <= gKb_Info[i].Xe + gAio_Info[Aio_num].kb_x && gTpInfo.y[0] <= gKb_Info[i].Ye + gAio_Info[Aio_num].kb_y && Kb_flag == 0)
			{
				if (gKb_Info[i].press_id != 0xFFFF)
				{

					LT_ReadFlash(buff1, addr_index[6] + 12 * gKb_Info[i].press_id, 12);
					pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
					pic_w = buff1[4] + (buff1[5] << 8);
					pic_h = buff1[6] + (buff1[7] << 8);
					pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
					pic_flag = buff1[11];

					LT268_dispaly_CutPicture(gAio_Info[Aio_num].kb_x + gKb_Info[i].Xs, gAio_Info[Aio_num].kb_y + gKb_Info[i].Ys,
											 gKb_Info[i].Xs, gKb_Info[i].Ys, gKb_Info[i].Xe - gKb_Info[i].Xs + 1, gKb_Info[i].Ye - gKb_Info[i].Ys + 1,
											 pic_w, pic_add, pic_len, pic_flag);
				}
				Kb_num = i;
				Kb_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}

	// raise
	if (gTpInfo.sta == 0 && AioKb_flag == 1 && Kb_flag == 1)
	{

		LT_ReadFlash(buff1, addr_index[6] + 12 * gAio_Info[Aio_num].kb_id, 12);
		PICINFO[0].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		PICINFO[0].w = buff1[4] + (buff1[5] << 8);
		PICINFO[0].h = buff1[6] + (buff1[7] << 8);
		PICINFO[0].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		PICINFO[0].flag = buff1[11];
		PICINFO[0].x = gAio_Info[Aio_num].kb_x;
		PICINFO[0].y = gAio_Info[Aio_num].kb_y;

		if ((gKb_Info[Kb_num].press_id != 0xFFFF && gKb_Info[Kb_num].Keyvalue != 0xF3) || CapsLock == 1)
		{
			LT268_dispaly_CutPicture(gAio_Info[Aio_num].kb_x + gKb_Info[Kb_num].Xs, gAio_Info[Aio_num].kb_y + gKb_Info[Kb_num].Ys,
									 gKb_Info[Kb_num].Xs, gKb_Info[Kb_num].Ys, gKb_Info[Kb_num].Xe - gKb_Info[Kb_num].Xs + 1, gKb_Info[Kb_num].Ye - gKb_Info[Kb_num].Ys + 1,
									 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);
		}

		if (gKb_Info[Kb_num].Keyvalue == 0xF0) // cancel
		{
			AioKb_flag = 0;
			if (Pop_up_flag == 0)
				Display_page(pic_id_temp);
			else if (Pop_up_flag == 1)
			{

				Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF1) // confirm
		{

			for (uint16_t j = 0; j < input_len; j++)
			{
				var[gAio_Info[Aio_num].p_add * 2 + j] = Display_buff[j];
			}

			var[gAio_Info[Aio_num].p_add * 2 + input_len] = 0x00;
			var[gAio_Info[Aio_num].p_add * 2 + input_len + 1] = 0x00;

			if (gAio_Info[Aio_num].Code == 0xC009)
			{
				rebuf[3] = 0x41;
				rebuf[4] = gAio_Info[Aio_num].p_add >> 8;
				rebuf[5] = gAio_Info[Aio_num].p_add & 0xFF;
				for (uint8_t j = 0; j < input_len; j++)
				{
					rebuf[6 + j] = var[gAio_Info[Aio_num].p_add * 2 + j];
				}
				if (input_len % 2 > 0)
				{
					rebuf[6 + input_len] = var[gAio_Info[Aio_num].p_add * 2 + input_len];
					LT_SendData_CRC_Frame(rebuf, 3 + input_len + 1);
				}
				else
					LT_SendData_CRC_Frame(rebuf, 3 + input_len);
			}

			if (Pop_up_flag == 0)
				Display_page(pic_id_temp);
			else if (Pop_up_flag == 1)
			{
				Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF2) // backspace
		{
			if (input_len > 0)
			{
				Cusor_time = 0;
				input_len--;
			}
			else
			{
				Cusor_time = 0;
				input_len = 0;
			}

			Display_buff[input_len] = 0x00;

			LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
							 LAY_BUFF1, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, gAio_Info[Aio_num].fcolor, Black, 0, 1, PICINFO[0], gAio_Info[Aio_num].input_mode,
							 gAio_Info[Aio_num].dp_x + gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y,
							 PICINFO[0].x + PICINFO[0].w, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y + gAio_Info[Aio_num].zk_h - 1,
							 0, 0, Display_buff, input_len);

			input_w = data_w;
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF3) // Caps lock
		{
			if (CapsLock == 0)
				CapsLock = 1;
			else
				CapsLock = 0;
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF4)
		{
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF5)
		{
			LT268_dispaly_CutPicture(gAio_Info[Aio_num].kb_x + gAio_Info[Aio_num].dp_x, gAio_Info[Aio_num].kb_y + gAio_Info[Aio_num].dp_y,
									 gAio_Info[Aio_num].dp_x, gAio_Info[Aio_num].dp_y, PICINFO[0].w - gAio_Info[Aio_num].dp_x, gAio_Info[Aio_num].zk_h,
									 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

			memset(Display_buff, 0, input_len);
			input_len = 0;
			input_w = 0;
		}
		else // Normal key value
		{
			if (gAio_Info[Aio_num].p_len * 2 > input_len)
			{
				if (CapsLock == 1)
				{
					Display_buff[input_len] = (gKb_Info[Kb_num].Keyvalue >> 8) & 0xFF;
				}
				else
				{
					Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xFF;
				}
				input_len++;
			}

			LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
							 LAY_BUFF1, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, gAio_Info[Aio_num].fcolor, Black, 0, 1, PICINFO[0], gAio_Info[Aio_num].input_mode,
							 gAio_Info[Aio_num].dp_x + gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y,
							 PICINFO[0].x + PICINFO[0].w, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y + gAio_Info[Aio_num].zk_h - 1,
							 0, 0, Display_buff, input_len);

			input_w = data_w;
		}
		Kb_flag = 0;
	}
}

/***********************************************************************************
 * Function Name : GBK_input
 * Description   : Touch detection of GBK keyboard.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void GBK_input(void)
{
	uint8_t res = 0;
	uint16_t i = 0, l = 0;
	uint8_t rebuf[50];
	uint8_t buff1[12] = {0};
	uint16_t k = 0;
	uint32_t zk_addr = 0;
	uint32_t color;

	// press down
	if (gTpInfo.sta && GBKioKb_flag == 0)
	{
		for (i = 0; i < GBKio_count; i++)
		{
			if (gTpInfo.x[0] >= gGBKio_Info[i].Xs && gTpInfo.y[0] >= gGBKio_Info[i].Ys && gTpInfo.x[0] <= gGBKio_Info[i].Xe && gTpInfo.y[0] <= gGBKio_Info[i].Ye && GBKio_flag == 0 && button_Press_flag == 0)
			{

				GBKio_num = i;
				GBKio_flag = 1;
				button_Press_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}

	// raise
	if (gTpInfo.sta == 0 && GBKio_flag == 1 && GBKioKb_flag == 0)
	{
		if (Pop_up_flag == 1) // pop-up window
		{
		}

		LT_ReadFlash(buff1, addr_index[6] + 12 * gGBKio_Info[GBKio_num].kb_id, 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		// Record keyboard background information
		PICINFO[0].addr = pic_add;
		PICINFO[0].w = pic_w;
		PICINFO[0].h = pic_h;
		PICINFO[0].len = pic_len;
		PICINFO[0].flag = pic_flag;
		PICINFO[0].x = gGBKio_Info[GBKio_num].kb_x;
		PICINFO[0].y = gGBKio_Info[GBKio_num].kb_y;

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			// display keyboard
			if (PICINFO[0].flag == 0)
				LT268_TFT_ShowPicture(PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
			if (PICINFO[0].flag == 1)
				LT268_TFT_ShowPicture_Png(PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
			if (PICINFO[0].flag == 2)
				LT268_TFT_ShowPicture_Png_Pixel(PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr);
		}

		/*Dynamic picture coverage judgment*/
		GBKioKb_flag = 1;
		gGBKio_Info[GBKio_num].Xs = gGBKio_Info[GBKio_num].kb_x;
		gGBKio_Info[GBKio_num].Ys = gGBKio_Info[GBKio_num].kb_y;
		gGBKio_Info[GBKio_num].Xe = gGBKio_Info[GBKio_num].kb_x + pic_w;
		gGBKio_Info[GBKio_num].Ye = gGBKio_Info[GBKio_num].kb_y + pic_h;

		LT_ReadFlash(buff1, addr_index[2] + gGBKio_Info[GBKio_num].py_zk * 8, 4);
		gGBKio_Info[GBKio_num].py_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		LT_ReadFlash(buff1, addr_index[2] + gGBKio_Info[GBKio_num].zk_id * 8, 4);
		gGBKio_Info[GBKio_num].zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		
		cur_x = gGBKio_Info[GBKio_num].dp_x + gGBKio_Info[GBKio_num].kb_x;
		cur_y = gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y;
		buff1[0] = '|';
		buff1[1] = 0;

		if (gGBKio_Info[GBKio_num].cursor_color == 0)
			color = Black;
		else
			color = White;

//		cur_w = gGBKio_Info[GBKio_num].zk_w / 2;
		cur_w = gGBKio_Info[GBKio_num].zk_w;

		button_Press_flag = 0;
		input_len = 0;
		GBK_PY_length = 0;
		CapsLock = 0;
		GBK_CN_EN = 0;
		input_w = 0;
		memset(Display_buff, 0, sizeof(Display_buff));

		pic_id_temp = pic_id;
		pic_id = gGBKio_Info[GBKio_num].kb_id;

		if (gGBKio_Info[GBKio_num].scan_mode == 1)
		{
			for (k = 0; k < gGBKio_Info[GBKio_num].p_len * 2; k++)
			{

				Display_buff[k] = var[gGBKio_Info[GBKio_num].p_add * 2 + k];
				if (var[gGBKio_Info[GBKio_num].p_add * 2 + k] == 0x00 && var[gGBKio_Info[GBKio_num].p_add * 2 + k + 1] == 0x00)
					break;
			}
			input_len = k;

			// Display GBK font on keyboard
			LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, White, 0, 1, PICINFO[0], 0,
							 gGBKio_Info[GBKio_num].dp_x + gGBKio_Info[GBKio_num].kb_x, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y,
							 PICINFO[0].x + PICINFO[0].w, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
							 0, 0, Display_buff, input_len);

			input_w = data_w;
			
			LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
							 cur_x + input_w, cur_y, cur_x + input_w + cur_w + 1, cur_y + gGBKio_Info[GBKio_num].zk_h - 1, 
							 0, 0, buff1, 1);
			
		}
		else
		{
			LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
							 cur_x, cur_y, cur_x + cur_w + 1, cur_y + gGBKio_Info[GBKio_num].zk_h - 1, 
							 0, 0, buff1, 1);
		}

		Get_Touch_info(gGBKio_Info[GBKio_num].kb_id);
		GBKio_flag = 0;
		memset(GBK_PY_buff, 0, 6);
		Cusor_time = 0;
	}

	// press down within the range of keyboard
	if (gTpInfo.sta && GBKioKb_flag == 1 && GBKio_flag == 0)
	{
		for (i = 0; i < Kb_count; i++)
		{
			if (gTpInfo.x[0] >= gKb_Info[i].Xs + gGBKio_Info[GBKio_num].kb_x && gTpInfo.y[0] >= gKb_Info[i].Ys + gGBKio_Info[GBKio_num].kb_y && gTpInfo.x[0] <= gKb_Info[i].Xe + gGBKio_Info[GBKio_num].kb_x && gTpInfo.y[0] <= gKb_Info[i].Ye + gGBKio_Info[GBKio_num].kb_y && Kb_flag == 0)
			{
				if (gKb_Info[i].press_id != 0xFFFF)
				{
					LT_ReadFlash(buff1, addr_index[6] + 12 * gKb_Info[i].press_id, 12);
					pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
					pic_w = buff1[4] + (buff1[5] << 8);
					pic_h = buff1[6] + (buff1[7] << 8);
					pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
					pic_flag = buff1[11];

					LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gKb_Info[i].Xs, gGBKio_Info[GBKio_num].kb_y + gKb_Info[i].Ys,
											 gKb_Info[i].Xs, gKb_Info[i].Ys, gKb_Info[i].Xe - gKb_Info[i].Xs + 1, gKb_Info[i].Ye - gKb_Info[i].Ys + 1,
											 pic_w, pic_add, pic_len, pic_flag);
				}
				Kb_num = i;
				Kb_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}

		if (GBK_PY_length > 0 && Kb_flag == 0 && GBK_PY_num > 0)
		{
			choice_GBK();
		}
	}

	// raise
	if (gTpInfo.sta == 0 && GBKioKb_flag == 1 && GBKio_flag == 0 && Kb_flag == 1)
	{
		LT_ReadFlash(buff1, addr_index[6] + 12 * gGBKio_Info[GBKio_num].kb_id, 12);
		PICINFO[0].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		PICINFO[0].w = buff1[4] + (buff1[5] << 8);
		PICINFO[0].h = buff1[6] + (buff1[7] << 8);
		PICINFO[0].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		PICINFO[0].flag = buff1[11];
		PICINFO[0].x = gGBKio_Info[GBKio_num].kb_x;
		PICINFO[0].y = gGBKio_Info[GBKio_num].kb_y;

		if ((gKb_Info[Kb_num].press_id != 0xFFFF && gKb_Info[Kb_num].Keyvalue != 0xF3 && gKb_Info[Kb_num].Keyvalue != 0xF4) || (CapsLock == 1 && gKb_Info[Kb_num].Keyvalue == 0xF3) || (GBK_CN_EN == 1 && gKb_Info[Kb_num].Keyvalue == 0xF4))
		{
			LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gKb_Info[Kb_num].Xs, gGBKio_Info[GBKio_num].kb_y + gKb_Info[Kb_num].Ys,
									 gKb_Info[Kb_num].Xs, gKb_Info[Kb_num].Ys, gKb_Info[Kb_num].Xe - gKb_Info[Kb_num].Xs + 1, gKb_Info[Kb_num].Ye - gKb_Info[Kb_num].Ys + 1,
									 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);
		}

		if (GBK_PY_length == 0 && CapsLock == 1) // Pinyin is not entered and is in uppercase status
		{
			if (gKb_Info[Kb_num].Keyvalue == 0xF0) // cancel
			{
				GBKioKb_flag = 0;
				if (Pop_up_flag == 0)
					Display_page(pic_id_temp);
				else if (Pop_up_flag == 1)
				{
					Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF1) // confirm
			{
				for (uint16_t j = 0; j < input_len; j++)
				{
					var[gGBKio_Info[GBKio_num].p_add * 2 + j] = Display_buff[j];
				}

				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len] = 0x00;
				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len + 1] = 0x00;

				if (gGBKio_Info[GBKio_num].Code == 0xC00A) // Serial port feedback
				{
					rebuf[3] = 0x41;
					rebuf[4] = gGBKio_Info[GBKio_num].p_add >> 8;
					rebuf[5] = gGBKio_Info[GBKio_num].p_add & 0xFF;

					if (input_len != 0)
					{
						for (uint16_t j = 0; j < input_len; j++)
						{
							rebuf[6 + j] = var[gGBKio_Info[GBKio_num].p_add * 2 + j];
						}
						if (input_len % 2 == 0)
							LT_SendData_CRC_Frame(rebuf, 3 + input_len);
						else
						{
							rebuf[6 + input_len] = var[gGBKio_Info[GBKio_num].p_add * 2 + input_len];
							LT_SendData_CRC_Frame(rebuf, 3 + input_len + 1);
						}
					}
					else if (input_len == 0)
					{
						rebuf[6] = 0x00;
						rebuf[7] = 0x00;
						LT_SendData_CRC_Frame(rebuf, 5);
					}
				}
				if (Pop_up_flag == 0)
					Display_page(pic_id_temp);
				else if (Pop_up_flag == 1)
				{
					Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF2) // backspace
			{
				if (input_len > 0)
				{
					for (l = 0; l < input_len;)
					{
						if (Display_buff[l] <= 0x7F)
						{
							l++;
							if (l == input_len)
							{
								Display_buff[input_len - 1] = 0x00;
								input_len--;
							}
						}
						else
						{
							l += 2;
							if (l == input_len)
							{
								Display_buff[input_len - 1] = 0x00;
								Display_buff[input_len - 2] = 0x00;
								input_len -= 2;
							}
						}
					}

					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
									 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
									 PICINFO[0].x + PICINFO[0].w, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
									 0, 0, Display_buff, input_len);

					input_w = data_w;
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF3) // Caps lock
			{
				if (CapsLock == 0)
					CapsLock = 1;
				else
					CapsLock = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF4) // Chinese and English input method switching
			{
				if (GBK_CN_EN == 0)
					GBK_CN_EN = 1;
				else
					GBK_CN_EN = 0; // Pinyin input
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF5) // clear display box of font
			{
				LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
										 gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].dp_y, input_w, gGBKio_Info[GBKio_num].zk_h,
										 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

				memset(Display_buff, 0, input_len);
				input_len = 0;
				input_w = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF7) // move
			{
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF8) // move
			{
			}
			else
			{
				if (gGBKio_Info[GBKio_num].p_len * 2 > input_len)
				{
					Display_buff[input_len] = (gKb_Info[Kb_num].Keyvalue >> 8) & 0xFF;
					input_len++;

					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
									 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
									 PICINFO[0].x + PICINFO[0].w, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
									 0, 0, Display_buff, input_len);

					input_w = data_w;
				}
			}
		}
		else if (GBK_PY_length == 0 && GBK_CN_EN == 1) // English input, pinyin has not been input
		{
			if (gKb_Info[Kb_num].Keyvalue == 0xF0) // cancel
			{
				GBKioKb_flag = 0;
				Display_page(pic_id_temp);
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF1) // comfirm
			{
				for (uint16_t j = 0; j < input_len; j++)
				{
					var[gGBKio_Info[GBKio_num].p_add * 2 + j] = Display_buff[j];
				}

				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len] = 0x00;
				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len + 1] = 0x00;

				if (gGBKio_Info[GBKio_num].Code == 0xC00A) // Serial port feedback
				{
					rebuf[3] = 0x41;
					rebuf[4] = gGBKio_Info[GBKio_num].p_add >> 8;
					rebuf[5] = gGBKio_Info[GBKio_num].p_add & 0xFF;

					if (input_len != 0)
					{
						for (uint16_t j = 0; j < input_len; j++)
						{
							rebuf[6 + j] = var[gGBKio_Info[GBKio_num].p_add * 2 + j];
						}
						if (input_len % 2 == 0)
							LT_SendData_CRC_Frame(rebuf, 3 + input_len);
						else
						{
							rebuf[6 + input_len] = var[gGBKio_Info[GBKio_num].p_add * 2 + input_len];
							LT_SendData_CRC_Frame(rebuf, 3 + input_len + 1);
						}
					}
					else if (input_len == 0)
					{
						rebuf[6] = 0x00;
						rebuf[7] = 0x00;
						LT_SendData_CRC_Frame(rebuf, 5);
					}
				}
				Display_page(pic_id_temp);
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF2) // backspace
			{

				if (input_len > 0)
				{
					for (l = 0; l < input_len;)
					{
						if (Display_buff[l] <= 0x7F)
						{
							l++;
							if (l == input_len)
							{
								Display_buff[input_len - 1] = 0x00;
								input_len--;
							}
						}
						else
						{
							l += 2;
							if (l == input_len)
							{
								Display_buff[input_len - 1] = 0x00;
								Display_buff[input_len - 2] = 0x00;
								input_len -= 2;
							}
						}
					}

					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
									 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
									 PICINFO[0].x + PICINFO[0].w, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
									 0, 0, Display_buff, input_len);

					input_w = data_w;
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF3) // Caps lock
			{
				if (CapsLock == 0)
					CapsLock = 1;
				else
					CapsLock = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF4) // Chinese and English input switching
			{
				GBK_CN_EN = 0; // Pinyin input
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF5) // clear display box of font
			{

				LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
										 gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].dp_y, input_w, gGBKio_Info[GBKio_num].zk_h,
										 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

				memset(Display_buff, 0, input_len);
				input_len = 0;
				input_w = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF7 || gKb_Info[Kb_num].Keyvalue == 0xF8) // move
			{
			}
			else
			{
				if (gGBKio_Info[GBKio_num].p_len * 2 > input_len)
				{
					Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xFF;
					input_len++;

					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
									 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
									 PICINFO[0].x + PICINFO[0].w, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
									 0, 0, Display_buff, input_len);

					input_w = data_w;
				}
			}
		}
		else // Pinyin input status
		{
			if (gKb_Info[Kb_num].Keyvalue == 0xF0) // cancel
			{
				GBKioKb_flag = 0;
				Display_page(pic_id_temp);
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF1) // comfirm
			{
				for (uint16_t j = 0; j < input_len; j++)
				{
					var[gGBKio_Info[GBKio_num].p_add * 2 + j] = Display_buff[j];
				}

				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len] = 0x00;
				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len + 1] = 0x00;

				if (gGBKio_Info[GBKio_num].Code == 0xC00A) // Serial port feedback
				{
					rebuf[3] = 0x41;
					rebuf[4] = gGBKio_Info[GBKio_num].p_add >> 8;
					rebuf[5] = gGBKio_Info[GBKio_num].p_add & 0xFF;

					if (input_len != 0)
					{
						for (uint16_t j = 0; j < input_len; j++)
						{
							rebuf[6 + j] = var[gGBKio_Info[GBKio_num].p_add * 2 + j];
						}
						if (input_len % 2 == 0)
							LT_SendData_CRC_Frame(rebuf, 3 + input_len);
						else
						{
							rebuf[6 + input_len] = var[gGBKio_Info[GBKio_num].p_add * 2 + input_len];
							LT_SendData_CRC_Frame(rebuf, 3 + input_len + 1);
						}
					}
					else if (input_len == 0)
					{
						rebuf[6] = 0x00;
						rebuf[7] = 0x00;
						LT_SendData_CRC_Frame(rebuf, 5);
					}
				}
				Display_page(pic_id_temp);
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF2)
			{
				if (GBK_PY_length == 0)
				{
					if (input_len > 0)
					{
						for (l = 0; l < input_len;)
						{
							if (Display_buff[l] <= 0x7F)
							{
								l++;
								if (l == input_len)
								{
									Display_buff[input_len - 1] = 0x00;
									input_len--;
									break;
								}
							}
							else
							{
								l += 2;
								if (l == input_len)
								{
									Display_buff[input_len - 1] = 0x00;
									Display_buff[input_len - 2] = 0x00;
									input_len -= 2;
									break;
								}
							}
						}

						LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
										 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
										 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
										 PICINFO[0].x + PICINFO[0].w, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
										 0, 0, Display_buff, input_len);

						input_w = data_w;
					}
				}
				else if (GBK_PY_length > 0)
				{
					GBK_PY_length--;
					GBK_linenum = 0;
					GBK_PY_buff[GBK_PY_length] = 0x00;
					Display_PY_GBK();
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF3) // Caps lock
			{
				if (CapsLock == 0)
					CapsLock = 1;
				else
					CapsLock = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF4) // English input
			{
				if (GBK_CN_EN == 0)
					GBK_CN_EN = 1;
				else
					GBK_CN_EN = 0; // Pinyin input
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF5) // clear display box of font
			{
				LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
										 gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].dp_y, input_w, gGBKio_Info[GBKio_num].zk_h,
										 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

				memset(Display_buff, 0, input_len);
				input_len = 0;
				input_w = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF7) // move
			{
				if (GBK_PY_length > 0)
				{
					if (GBK_linenum > 0)
						GBK_linenum--;
					Display_PY_GBK();
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF8)
			{
				GBK_linenum++;
				Display_PY_GBK();
			}
			else
			{
				if (GBK_PY_length == 0 && ((gKb_Info[Kb_num].Keyvalue & 0x00FF) > 122 || (gKb_Info[Kb_num].Keyvalue & 0x00FF) < 97))
				{
					if (gGBKio_Info[GBKio_num].p_len * 2 > input_len)
					{
						Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xFF;
						input_len++;

						LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
										 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Red, 0, 1, PICINFO[0], 0,
										 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
										 gGBKio_Info[GBKio_num].kb_x + PICINFO[0].w - gGBKio_Info[GBKio_num].dp_x * 2, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].zk_h - 1,
										 0, 0, Display_buff, input_len);

						input_w = data_w;
					}
				}
				else
				{
					GBK_linenum = 0;
					if (CapsLock == 0) // Caps lock
					{
						if ((gKb_Info[Kb_num].Keyvalue & 0x00FF) != 0x00 && ((gKb_Info[Kb_num].Keyvalue & 0x00FF) <= 122 || (gKb_Info[Kb_num].Keyvalue & 0x00FF) >= 97))
						{
							if (GBK_PY_length == 0)
							{
								GBK_PY_buff[GBK_PY_length] = gKb_Info[Kb_num].Keyvalue & 0x00FF;
								GBK_PY_length++;
								Display_PY_GBK();
							}
							else if (GBK_PY_length < 6 && GBK_PY_num > 0)
							{
								GBK_PY_buff[GBK_PY_length] = gKb_Info[Kb_num].Keyvalue & 0x00FF;
								GBK_PY_length++;
								Display_PY_GBK();
							}
						}
					}
				}
			}
		}

		Kb_flag = 0;
	}

	if (gTpInfo.sta == 0 && GBKioKb_flag == 1 && GBKio_flag == 0 && Kb_flag == 2)
	{
		// select chinese
		LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].py_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].py_y,
								 gGBKio_Info[GBKio_num].py_x, gGBKio_Info[GBKio_num].py_y, gGBKio_Info[GBKio_num].py_w * 6, gGBKio_Info[GBKio_num].py_h,
								 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

		LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].cn_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].cn_y,
								 gGBKio_Info[GBKio_num].cn_x, gGBKio_Info[GBKio_num].cn_y, (gGBKio_Info[GBKio_num].py_w + gGBKio_Info[GBKio_num].spacing) * 8, gGBKio_Info[GBKio_num].py_h,
								 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

		LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
						 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
						 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
						 PICINFO[0].x + PICINFO[0].w, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
						 0, 0, Display_buff, input_len);

		input_w = data_w;
		Kb_flag = 0;
	}
}

/***********************************************************************************
* Function Name : Display_encoder
* Description   : Run encoder.
* Input         : - type: encoder info sources
				  - buff: encoder info
* Output        : None
* Return        : None
************************************************************************************/
void Display_encoder(uint8_t *buff, uint8_t type)
{
	uint8_t i;
	uint8_t len, loop;
	int16_t sum = 0, V_max, V_min;
	uint16_t p_add = 0, step;
	uint8_t rebuf[50];
	uint16_t reg_addr;

	len = buff[1];

	if (type == 4 || type == 0x84) // multi button control
	{
		for (i = 0; i < 32; i += 4)
		{
			reg_addr = (buff[i + 2] + (buff[i + 2 + 1] << 8));
			Var_AddrRemapping(&reg_addr);

			if (reg_addr != 0xFFFF && reg_addr <= VAR_ADDR_E)
			{
				var[reg_addr * 2] = buff[i + 2 + 3];
				var[reg_addr * 2 + 1] = buff[i + 2 + 2];
				
				if (reg_addr >= VAR_ADDR_S)
				{
					reg_addr = buff[i] + (buff[i + 1] << 8);
					Var_AddrRemapping(&reg_addr);
					reg_operation(reg_addr);
				}
			}
		}
		if (type == 0x84)
		{
			rebuf[3] = 0x41;
			for (i = 0; i < 8; i++)
			{
				rebuf[4 * i + 4] = buff[4 * i + 2 + 1];
				rebuf[4 * i + 5] = buff[4 * i + 2];
				rebuf[4 * i + 6] = buff[4 * i + 2 + 3];
				rebuf[4 * i + 7] = buff[4 * i + 2 + 2];
			}
			LT_SendData_CRC_Frame(rebuf, 33);
		}

		if ((buff[0] + (buff[1] << 8)) < addr_index[7])
		{
			Display_page(buff[0] + (buff[1] << 8));
		}
		else
		{
			page_date_update(pic_id);
		}
	}
	else if (buff[0] == 1 || buff[0] == 0x81)
	{
		for (i = 0; i < (len - 2); i += 4)
		{
			reg_addr = (buff[i + 4] + (buff[i + 4 + 1] << 8));
			Var_AddrRemapping(&reg_addr);
			if (reg_addr != 0xFFFF && reg_addr <= VAR_ADDR_E)
			{
				var[reg_addr * 2] = buff[i + 4 + 3];
				var[reg_addr * 2 + 1] = buff[i + 4 + 2];
				if (reg_addr >= VAR_ADDR_S)
				{
					reg_addr = buff[i] + (buff[i + 1] << 8);
					Var_AddrRemapping(&reg_addr);
					reg_operation(reg_addr);
				}
			}
		}

		if (buff[0] == 0x81)
		{
			rebuf[3] = 0x41;
			for (i = 0; i < 8; i++)
			{
				rebuf[4 * i + 4] = buff[4 * i + 4 + 1];
				rebuf[4 * i + 5] = buff[4 * i + 4];
				rebuf[4 * i + 6] = buff[4 * i + 4 + 3];
				rebuf[4 * i + 7] = buff[4 * i + 4 + 2];
			}
			LT_SendData_CRC_Frame(rebuf, 33);
		}

		if ((buff[2] + (buff[3] << 8)) < addr_index[7])
		{
			Display_page(buff[2] + (buff[3] << 8));
		}
		else
		{
			page_date_update(pic_id);
		}
	}
	else if (buff[0] == 2 || buff[0] == 0x82)
	{
		p_add = buff[2] + (buff[3] << 8);
		V_max = buff[4] + (buff[5] << 8);
		V_min = buff[6] + (buff[7] << 8);
		step = buff[8] + (buff[9] << 8);
		loop = buff[10];
		sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		
		Var_AddrRemapping(&p_add);
		
		if (buff[10] == 1) // ��
		{
			if (sum + step > V_max)
			{
				if (loop == 1) // ѭ��
				{
					var[p_add * 2] = V_min >> 8 & 0xFF;
					var[p_add * 2 + 1] = V_min & 0xFF;
				}
				else
				{
					var[p_add * 2] = V_max >> 8 & 0xFF;
					var[p_add * 2 + 1] = V_max & 0xFF;
				}
			}
			else
			{
				sum += step;
				var[p_add * 2] = sum >> 8 & 0xFF;
				var[p_add * 2 + 1] = sum & 0xFF;
			}
		}
		else if (buff[10] == 0) // ��
		{
			if (sum - step < V_min)
			{
				if (loop == 2)
				{
					var[p_add * 2] = V_max >> 8 & 0xFF;
					var[p_add * 2 + 1] = V_max & 0xFF;
				}
				else
				{
					var[p_add * 2] = V_min >> 8 & 0xFF;
					var[p_add * 2 + 1] = V_min & 0xFF;
				}
			}
			else
			{
				sum -= step;
				var[p_add * 2] = sum >> 8 & 0xFF;
				var[p_add * 2 + 1] = sum & 0xFF;
			}
		}
		if (buff[0] == 0x82)
		{
			rebuf[3] = 0x41;
			rebuf[4] = buff[3];
			rebuf[5] = buff[2];
			rebuf[6] = var[p_add * 2];
			rebuf[7] = var[p_add * 2 + 1];
			LT_SendData_CRC_Frame(rebuf, 5);
		}
		if (p_add >= VAR_ADDR_S)
		{
			reg_operation(p_add);
		}
		page_date_update(pic_id);
	}
	else if (buff[0] == 3 || buff[0] == 0x83)
	{
		if (knob_flag == 0)
			knob_flag = 1;
		else if (knob_flag == 1)
			knob_flag = 0;
	}
}

void get_encoder(uint8_t type, uint8_t *buff, uint16_t addr)
{
	uint16_t len;
	uint16_t len1 = 0;
	uint8_t i;

	len = buff[4] + (buff[5] << 8);
	len1 = 8;
	Check_box_add = buff[6] + (buff[7] << 8);

//	Var_AddrRemapping(&Check_box_add);

	for (i = 0; i < 255; i++)
	{
		gEncoder_addr[i] = len1 + addr;
		len1 = len1 + buff[len1 + 1] + 2;
		if (len1 - 6 >= len)
			break;
	}

	gEncoderFlag = 1;

	gEncoder_num = (var[Check_box_add * 2] << 8) + var[Check_box_add * 2 + 1];
	if (gEncoder_num > i)
		gEncoder_num = i;
	gEncoder_count = i;
}

uint8_t knob_dir = 0, SW_flag = 0, SW_flag4 = 0, key_time = 0;
uint8_t Encoder_read_Flag = 0, Encoder_Freetime = 0;
uint8_t Enc0 = 0, Enc1 = 0;
uint8_t EncNow;
uint16_t Encoder_time = 0;
static uint8_t EncOld, EncX = 0;

uint8_t Double_click_interval = 0;
uint8_t Long_press = 0;
uint8_t Encoder_type = 0;

/***********************************************************************************
 * Function Name : encoder
 * Description   : Detect encoder rotation and key.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void encoder(void)
{
	uint16_t addr;
	uint16_t p_add, step;
	uint8_t type;
	uint8_t rebuf[10];
	int16_t V_max, V_min, sum = 0;

	if (Enc0 == 0)
		EncOld = (PINA ? 0x02 : 0x00) + (PINB ? 0x01 : 0x00); // Remember the status of the encoder at the first call
	if (EncOld == 0x00 || EncOld == 0x03)
		Enc0 = 1;

	// According to the current status of two IO, they are combined into a hexadecimal 0x00 | 0x01 | 0x02 | 0x03
	EncNow = (PINA ? 0x02 : 0x00) + (PINB ? 0x01 : 0x00);

	if ((EncOld == 0x00 && EncNow == 0x02) || (EncOld == 0x03 && EncNow == 0x01))
		EncX = EncNow; // 00-10|11-01

	// turn right,00-10-11|11-01-00
	if ((EncOld == 0x00 && EncX == 0x02 && EncNow == 0x03) || (EncOld == 0x03 && EncX == 0x01 && EncNow == 0x00))
	{
		Encoder_Freetime = 0;
		EncOld = EncNow, EncX = 0;
		Backlight_count = 0;
		if (Backlight_flag == 0)
		{
			Backlight_flag = 1;
			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		}
		else 
		{
			if(EncType == 1)
			{
				if (knob_flag == 1) // Move right at knob control variable to increase
				{
					addr = gEncoder_addr[gEncoder_num];
					p_add = config_buff[addr + 2] + (config_buff[addr + 3] << 8);
					sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
					V_max = config_buff[addr + 4] + (config_buff[addr + 5] << 8);
					V_min = config_buff[addr + 6] + (config_buff[addr + 7] << 8);
					step = config_buff[addr + 8] + (config_buff[addr + 9] << 8);

					Var_AddrRemapping(&p_add);

					if (sum + step > V_max)
					{
						var[p_add * 2] = V_max >> 8 & 0xFF;
						var[p_add * 2 + 1] = V_max & 0xFF;
					}
					else
					{
						sum += step;

						var[p_add * 2] = sum >> 8 & 0xFF;
						var[p_add * 2 + 1] = sum & 0xFF;
					}

					if (config_buff[addr] == 0x83)
					{
						rebuf[3] = 0x41;
						rebuf[4] = config_buff[addr + 3];
						rebuf[5] = config_buff[addr + 2];
						rebuf[6] = var[p_add * 2];
						rebuf[7] = var[p_add * 2 + 1];
						LT_SendData_CRC_Frame(rebuf, 5);
					}
				
					if (p_add >= VAR_ADDR_S)
						reg_operation(p_add);

					page_date_update(pic_id);

				}
				else
				{
					gEncoder_num++;
					if (gEncoder_num > gEncoder_count)
						gEncoder_num = 0;
					var[Check_box_add * 2] = (gEncoder_num >> 8) & 0xFF;
					var[Check_box_add * 2 + 1] = gEncoder_num & 0xFF;
					page_date_update(pic_id);
				}
			}
			else
			{
				if (Enc1 == 0)
				{
					Enc1 = 1;
					knob_dir = 1;
					Encoder_Freetime = 0;
				}
				else
				{
					if (knob_dir == 1)
					{
						Enc1 = 0;
						knob_dir = 0;

						if (knob_flag == 1) // Move right at knob control variable to increase
						{
							addr = gEncoder_addr[gEncoder_num];
							p_add = config_buff[addr + 2] + (config_buff[addr + 3] << 8);
							sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
							V_max = config_buff[addr + 4] + (config_buff[addr + 5] << 8);
							V_min = config_buff[addr + 6] + (config_buff[addr + 7] << 8);
							step = config_buff[addr + 8] + (config_buff[addr + 9] << 8);
							
							Var_AddrRemapping(&p_add);

							if (sum + step > V_max)
							{
								var[p_add * 2] = V_max >> 8 & 0xFF;
								var[p_add * 2 + 1] = V_max & 0xFF;
							}
							else
							{
								sum += step;

								var[p_add * 2] = sum >> 8 & 0xFF;
								var[p_add * 2 + 1] = sum & 0xFF;
							}

							if (config_buff[addr] == 0x83)
							{
								rebuf[3] = 0x41;
								rebuf[4] = config_buff[addr + 3];
								rebuf[5] = config_buff[addr + 2];
								rebuf[6] = var[p_add * 2];
								rebuf[7] = var[p_add * 2 + 1];
								LT_SendData_CRC_Frame(rebuf, 5);
							}
						
							if (p_add >= VAR_ADDR_S)
								reg_operation(p_add);

							page_date_update(pic_id);

						}
						else
						{
							gEncoder_num++;
							if (gEncoder_num > gEncoder_count)
								gEncoder_num = 0;
							var[Check_box_add * 2] = (gEncoder_num >> 8) & 0xFF;
							var[Check_box_add * 2 + 1] = gEncoder_num & 0xFF;
							page_date_update(pic_id);
						}
					}
					else
					{
						knob_dir = 1;
						Enc1 = 1;
					}
				}
			}
		}
	}

	if ((EncOld == 0x00 && EncNow == 0x01) || (EncOld == 0x03 && EncNow == 0x02))
		EncX = EncNow; // 00-01|11-10

	// turn left,00-01-11|11-10-00
	if ((EncOld == 0x00 && EncX == 0x01 && EncNow == 0x03) || (EncOld == 0x03 && EncX == 0x02 && EncNow == 0x00))
	{
		Encoder_Freetime = 0;
		EncOld = EncNow, EncX = 0;
		Backlight_count = 0;
		if (Backlight_flag == 0)
		{			
			Backlight_flag = 1;
			LT_BacklightSet(gDutyBuf[var[0x7001 * 2 + 1]]);
		}
		else 
		{
			if(EncType == 1)
			{
				if (knob_flag == 1) // At the knob control variable
				{
					addr = gEncoder_addr[gEncoder_num];
					p_add = config_buff[addr + 2] + (config_buff[addr + 3] << 8);
					sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
					V_max = config_buff[addr + 4] + (config_buff[addr + 5] << 8);
					V_min = config_buff[addr + 6] + (config_buff[addr + 7] << 8);
					step = config_buff[addr + 8] + (config_buff[addr + 9] << 8);
					
					Var_AddrRemapping(&p_add);

					if (sum - step < V_min)
					{
						var[p_add * 2] = V_min >> 8 & 0xFF;
						var[p_add * 2 + 1] = V_min & 0xFF;
					}
					else
					{
						sum -= step;
						var[p_add * 2] = sum >> 8 & 0xFF;
						var[p_add * 2 + 1] = sum & 0xFF;
					}
					if (config_buff[addr] == 0x83)
					{
						rebuf[3] = 0x41;
						rebuf[4] = config_buff[addr + 3];
						rebuf[5] = config_buff[addr + 2];
						rebuf[6] = var[p_add * 2];
						rebuf[7] = var[p_add * 2 + 1];
						LT_SendData_CRC_Frame(rebuf, 5);
					}
					if (p_add >= VAR_ADDR_S)
						reg_operation(p_add);

					page_date_update(pic_id);
				}
				else
				{
					if (gEncoder_num == 0)
						gEncoder_num = gEncoder_count;
					else
						gEncoder_num--;
					var[Check_box_add * 2] = (gEncoder_num >> 8) & 0xFF;
					var[Check_box_add * 2 + 1] = gEncoder_num & 0xFF;
					page_date_update(pic_id);
				}
			}
			else
			{
				if (Enc1 == 0) // First rotation
				{
					knob_dir = 2;
					Enc1 = 1;
					Encoder_Freetime = 0;
				}
				else // Second rotation within 1S between the first rotation
				{
					if (knob_dir == 2)
					{
						Enc1 = 0;
						knob_dir = 0;
						if (knob_flag == 1) // At the knob control variable
						{
							addr = gEncoder_addr[gEncoder_num];
							p_add = config_buff[addr + 2] + (config_buff[addr + 3] << 8);
							sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
							V_max = config_buff[addr + 4] + (config_buff[addr + 5] << 8);
							V_min = config_buff[addr + 6] + (config_buff[addr + 7] << 8);
							step = config_buff[addr + 8] + (config_buff[addr + 9] << 8);
							
							Var_AddrRemapping(&p_add);

							if (sum - step < V_min)
							{
								var[p_add * 2] = V_min >> 8 & 0xFF;
								var[p_add * 2 + 1] = V_min & 0xFF;
							}
							else
							{
								sum -= step;
								var[p_add * 2] = sum >> 8 & 0xFF;
								var[p_add * 2 + 1] = sum & 0xFF;
							}
							if (config_buff[addr] == 0x83)
							{
								rebuf[3] = 0x41;
								rebuf[4] = config_buff[addr + 3];
								rebuf[5] = config_buff[addr + 2];
								rebuf[6] = var[p_add * 2];
								rebuf[7] = var[p_add * 2 + 1];
								LT_SendData_CRC_Frame(rebuf, 5);
							}
							if (p_add >= VAR_ADDR_S)
								reg_operation(p_add);

							page_date_update(pic_id);
						}
						else
						{
							if (gEncoder_num == 0)
								gEncoder_num = gEncoder_count;
							else
								gEncoder_num--;
							var[Check_box_add * 2] = (gEncoder_num >> 8) & 0xFF;
							var[Check_box_add * 2 + 1] = gEncoder_num & 0xFF;
							page_date_update(pic_id);
						}
					}
					else
					{
						knob_dir = 2;
						Enc1 = 1;
					}
				}
			}
		}
	}

	if(SW_flag)
	{
		Backlight_count = 0;
		if (Backlight_flag == 0)
		{			
			SW_flag = 0;
			SW_flag4 = 0;
			Backlight_flag = 1;
			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		}
		else
		{
			if (SW_flag == 1)
			{
				SW_flag = 0;
				Enc1 = 0;
				knob_dir = 0;
				Display_encoder(&config_buff[gEncoder_addr[gEncoder_num]], 0);
			}
			else if (SW_flag4 == 3 && SW_flag == 4)	
			{
				SW_flag = 0;
				Enc1 = 0;
				knob_dir = 0;
				if ((config_buff[gEncoder_addr[gEncoder_num]] & 0x2F) == 0x24)
					type = 0x84;
				else
					type = 4;
				Display_encoder(&config_buff[gEncoder_addr[gEncoder_num] + 72], type);
			}
			else if (SW_flag4 == 2 && SW_flag == 3)
			{
				SW_flag = 0;
				Enc1 = 0;
				knob_dir = 0;
				if ((config_buff[gEncoder_addr[gEncoder_num]] & 0x4F) == 0x44)
					type = 0x84;
				else
					type = 4;
				Display_encoder(&config_buff[gEncoder_addr[gEncoder_num] + 37], type);
			}
			else if (SW_flag4 == 1 && SW_flag == 2)
			{
				SW_flag4 = 0;
				SW_flag = 0;
				Enc1 = 0;
				knob_dir = 0;
				if ((config_buff[gEncoder_addr[gEncoder_num]] & 0x8F) == 0x84)
					type = 0x84;
				else
					type = 4;
				Display_encoder(&config_buff[gEncoder_addr[gEncoder_num] + 2], type);
			}
		}
	}
	if (SW_flag4 == 2 || SW_flag4 == 3)
	{
		Backlight_count = 0;
		if (Read_Encoder_key == 1)
		{
			SW_flag4 = 0;
			Encoder_read_Flag = 0;
			Encoder_time = 0;
			key_time = 0;
		}
	}
}

/***********************************************************************************
 * Function Name : BackLight_control
 * Description   : Automatically adjust backlight.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void BackLight_control(void)
{
//#if (LT_TOUCH_FLAG == 1 || LT_TOUCH_FLAG == 2)
	if (Backlight_flag == 1)
	{
		if(Backlight_touch)
		{
			if(First_press == 1)
			{
				gTpInfo.sta = 0;          // disable touch function
				Backlight_count = 0;
				Backlight_flag = 1;
			}
			else
			{
				gTpInfo.sta = 0;
				Backlight_count = 0;
				Backlight_flag = 1;
				Backlight_touch = 0;      // enable touch function     
			}
		}
		
		if (gTpInfo.sta == 1) // count reset
		{
			Backlight_count = 0;
			Backlight_flag = 1;
			Backlight_touch = 0;
		}
		else if (Backlight_count >= ((var[VAR_BLDURATION * 2] << 8) + var[VAR_BLDURATION * 2 + 1 ]) * 100) 
		{
			if(pageSTART_flag==1)
			{
				Display_page(17);
				//var[0x200f*2+1] = Sleep_time_state;		
         printf("888888888888888888aaaaaaaaaa\r\n");				
			}
			else
			{
				LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);  // sleep
				Backlight_flag = 0;
				//var[0x200f*2+1] = 0;
				//var[0x2001*2+1] = 0;
				//Display_page(20);
				printf("999999999999999999aaaaaaaaaa\r\n");
			}
			Backlight_count = 0;
		}
	}
	else if (Backlight_flag == 0 && gTpInfo.sta == 1)
	{
		if (buzzer)
			touch_buzzer();
		gTpInfo.sta = 0;
		Backlight_touch = 1;
		Backlight_count = 0;
		Backlight_flag = 1;
		printf("78787878787aaaaaaaaaa\r\n");
		LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]); // operation
}
//#endif
	
}
